您如何找到远程 git 存储库的默认分支?
How do you find the default branch of a remote git repository?
不同的存储库以不同的方式命名其主要开发分支(例如 main
、gh-pages
、master
等),并且用于多个存储库的脚本需要一种自动化的方式来发现当前存储库的默认分支名称。
什么git
命令returns那个名字?
<a href="https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt---abbrev-refstrictloose" rel="nofollow noreferrer">git rev-parse --abbrev-ref</a> origin/HEAD
将打印 origin/<default-branch-name>
.
如果 origin
存储库更改其默认分支名称,则 <a href="https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emset-headem" rel="nofollow noreferrer">git remote set-head</a> origin -a
将检索新的默认分支名称。
不同的存储库以不同的方式命名其主要开发分支(例如 main
、gh-pages
、master
等),并且用于多个存储库的脚本需要一种自动化的方式来发现当前存储库的默认分支名称。
什么git
命令returns那个名字?
<a href="https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt---abbrev-refstrictloose" rel="nofollow noreferrer">git rev-parse --abbrev-ref</a> origin/HEAD
将打印 origin/<default-branch-name>
.
如果 origin
存储库更改其默认分支名称,则 <a href="https://git-scm.com/docs/git-remote#Documentation/git-remote.txt-emset-headem" rel="nofollow noreferrer">git remote set-head</a> origin -a
将检索新的默认分支名称。