简体   繁体   English

如何找到远程 git 存储库的默认分支?

[英]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.不同的存储库以不同的方式命名它们的主要开发分支(例如maingh-pagesmaster等),并且旨在与多个存储库一起使用的脚本需要一种自动化的方式来发现当前存储库的默认分支名称。

What git command returns that name?什么git命令返回该名称?

git rev-parse --abbrev-ref origin/HEAD will print origin/<default-branch-name> . git rev-parse --abbrev-ref origin/HEAD将打印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.如果origin存储库更改其默认分支名称,则git remote set-head origin -a将检索新的默认分支名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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