Quantcast
Channel: How do I get the current branch name in Git? - Stack Overflow
Viewing all articles
Browse latest Browse all 96

Answer by cagney for How do I get the current branch name in Git?

$
0
0

Using earlier ideas; assuming sha1 is 40 characters; and chasing references (yea, should delete the debug print lines :-):

git reflog | awk '$3 == "checkout:"&& (sha == "" || sha == $1 ) {  from=$(NF - 2)  to=$NF  print from, to, length(from) > "/dev/stderr"  if (length(from) != 40) { print from ; exit; }  sha=substr(from, 1, 7)  print sha > "/dev/stderr"}'

gives the raw output:

$ git statusHEAD detached at 147049c[...]$ ./gime-branch.sha47be8d2167641088b66bf8f5c2bf7d3da0c642c HEAD^ 40a47be8dmaster HEAD^ 6master

Viewing all articles
Browse latest Browse all 96

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>