Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replace instances of the string "master" with "main" in a git binary executable
package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"regexp"
)
func main() {
byt, err := ioutil.ReadFile(os.Args[1])
if err != nil {
fmt.Println(err)
return
}
re := regexp.MustCompile("master([^\x00]*)")
out := re.ReplaceAll(byt, []byte("main${1}\x00\x00"))
io.Copy(os.Stdout, bytes.NewBuffer(out))
}
@ear7h

This comment has been minimized.

Copy link
Owner Author

ear7h commented Jun 25, 2020

Run with:

go run git-decolonize.go $(which git) > git-decolonized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.