My team alternates between usage of dev and master as default branch for several repos and I would like to write a script that checks for the default branch when entering a
This question is a bit old but in case anyone comes across this more recently...
git remote show | awk '/HEAD branch/ {print $NF}'
That will also only display the branch name, not including any of the whitespace or other nonsense.
I like to save this using a couple git aliases (I have a bunch of useful aliases like this):
upstream-name = !git remote | egrep -o '(upstream|origin)' | tail -1
head-branch = !git remote show $(git upstream-name) | awk '/HEAD branch/ {print $NF}'
I use "upstream" and "origin" as my remotes almost 100% of the time ("upstream" when I go with a Fork & Pull workflow... which is often). Your use case may not need the upstream-name alias, I just find it useful.