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 works for me with Git 2.1.10, using a repository cloned from GitHub:
git branch -r --points-at refs/remotes/origin/HEAD
A major problem with this approach is that it lists every remote branch pointing to HEAD; however, the output includes a hint:
origin/HEAD -> origin/master
origin/master
origin/test123
So you can post-process the output with grep
or similar to find the one with the arrow:
git branch -r --points-at refs/remotes/origin/HEAD | grep '\->' | cut -d' ' -f5 | cut -d/ -f2