Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

master vs main #39

Open
OleksiyRudenko opened this issue Jan 2, 2021 · 0 comments
Open

master vs main #39

OleksiyRudenko opened this issue Jan 2, 2021 · 0 comments

Comments

@OleksiyRudenko
Copy link
Owner

OleksiyRudenko commented Jan 2, 2021

  1. 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)

  1. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant