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

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

$
0
0

Just the name of the current branch if on a branch, but if detached then print the current commit id:

git symbolic-ref --short HEAD 2>/dev/null || git rev-parse --short HEAD 

The first part will return an error if detached, and the second part will always print the current commit id.


Viewing all articles
Browse latest Browse all 96

Trending Articles



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