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

Answer by Silas Barta for How to get the current branch name in Git?

$
0
0

Found a command line solution of the same length as Oliver Refalo's, using good ol' awk:

git branch | awk '/^\*/{print $2}'

awk reads that as "do the stuff in {} on lines matching the regex". By default it assumes whitespace-delimited fields, so you print the second. If you can assume that only the line with your branch has the *, you can drop the ^. Ah, bash golf!


Viewing all articles
Browse latest Browse all 96

Trending Articles