Skip to content

master vs main #39

@OleksiyRudenko

Description

@OleksiyRudenko
  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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions