简体   繁体   中英

How do you find the default branch of a remote git repository?

Different repositories name their primary development branches differently (eg 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM