Skip to content

Instantly share code, notes, and snippets.



Created Nov 7, 2014
What would you like to do?
func current_branch(git_dir string) string {
head_bytes, err := ioutil.ReadFile(path.Join(git_dir, "HEAD"))
head := string(head_bytes)
if err != nil {
log.Fatal("Cannot open HEAD from ", git_dir)
r, _ := regexp.Compile("ref: ref/heads/(.+)")
match := r.FindStringSubmatch(head)
branch := match[1]
return branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment