4

Different repositories name their primary development branches differently (e.g. main, gh-pages, master, etc.), and scripts meant to work with multiple repositories need an automated way to discover the current repository's default branch name.

What git command returns that name?

Jeffrey Yasskin
  • 5,171
  • 2
  • 27
  • 39

1 Answers1

8

git rev-parse --abbrev-ref origin/HEAD will print origin/<default-branch-name>.

If the origin repository changes its default branch name, then git remote set-head origin -a will retrieve the new default branch name.

Jeffrey Yasskin
  • 5,171
  • 2
  • 27
  • 39
  • 5
    origin/HEAD may not always be available! If you create the repo and did not clone it, there's a good chance it won't be there! – tux3 May 06 '21 at 15:46