- Get default branch name
Option 1a. git remote show <remote_name> | grep 'HEAD branch' | cut -d' ' -f5
Option 1b. git branch -r --points-at refs/remotes/origin/HEAD | grep '\->' | cut -d' ' -f5 | cut -d/ -f2
Option 1c. git remote show <remote_name> | awk '/HEAD branch/ {print $NF}'
Option 1d.
upstream-name = !git remote | egrep -o '(upstream|origin)' | tail -1
head-branch = !git remote show $(git upstream-name) | awk '/HEAD branch/ {print $NF}'
Option 1e. git rev-parse --abbrev-ref origin/HEAD will print origin/<default-branch-name>
Option 1f. git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'
Option 1g. git remote show <remote_name> | grep "HEAD branch" | cut -d ":" -f 2
Option 1i.
( set -- `git ls-remote --symref origin HEAD`
test $1 = ref: && echo $2 )
NB. <remote_name> is normally origin)
- Assign an alias branch name and use it in scripts
Option 2a. git symbolic-ref refs/heads/default refs/heads/<default-branch>
Note: one can still checkout default as such and any operations with default branch will just update the bound branch pointer. Current branch will be the bound branch, however bash prompt still may show default
Option 1a.
git remote show <remote_name> | grep 'HEAD branch' | cut -d' ' -f5Option 1b.
git branch -r --points-at refs/remotes/origin/HEAD | grep '\->' | cut -d' ' -f5 | cut -d/ -f2Option 1c.
git remote show <remote_name> | awk '/HEAD branch/ {print $NF}'Option 1d.
Option 1e.
git rev-parse --abbrev-ref origin/HEADwill printorigin/<default-branch-name>Option 1f.
git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'Option 1g.
git remote show <remote_name> | grep "HEAD branch" | cut -d ":" -f 2Option 1i.
NB.
<remote_name>is normallyorigin)Option 2a.
git symbolic-ref refs/heads/default refs/heads/<default-branch>Note: one can still checkout
defaultas such and any operations withdefaultbranch will just update the bound branch pointer. Current branch will be the bound branch, however bash prompt still may showdefault