Skip to content

Instantly share code, notes, and snippets.

@ear7h
Created June 25, 2020 04:32
Show Gist options
  • Save ear7h/c23b65071edbb68d0b3c99a7982279b0 to your computer and use it in GitHub Desktop.
Save ear7h/c23b65071edbb68d0b3c99a7982279b0 to your computer and use it in GitHub Desktop.
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
Copy link
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