Quantcast
Viewing latest article 36
Browse Latest Browse All 96

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

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 latest article 36
Browse Latest Browse All 96

Trending Articles



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