不同的存储库以不同的方式命名它们的主要开发分支(例如 main
、gh-pages
、master
等),并且脚本旨在使用多个存储库需要一种自动方式来发现当前存储库的默认分支名称。
什么 git
命令返回那个名字?
最佳答案
<a href="https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt---abbrev-refstrictloose" rel="noreferrer noopener nofollow">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="noreferrer noopener nofollow">git remote set-head</a> origin -a
将检索新的默认分支名称。
关于git - 如何找到远程 git 存储库的默认分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62352646/