Git clone 不带master分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2015530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:00:37  来源:igfitidea点击:

Git clone does not bring master branch

gitremote-branch

提问by Pablo Fernandez

I have a remote repository http://github.com/fernandezpablo85/Test

我有一个远程存储库http://github.com/fernandezpablo85/Test

This repo has a masterbranch, but it's behind two other branches so when I clone it I get this warining:

这个 repo 有一个master分支,但它在另外两个分支后面,所以当我克隆它时,我得到了这个警告:

warning: remote HEAD refers to nonexistent ref, unable to checkout.

警告:远程 HEAD 指的是不存在的引用,无法结帐。

And also I don't get a local masterbranch (git branchshows nothing).

而且我也没有当地的master分支机构(git branch什么也没显示)。

I can fix the whole thing doing:

我可以解决整个事情:

git checkout -b master origin/master

git checkout -b master origin/master

But I was wondering why this happens? Is master supposed to be the more advancedbranch? Or is there something else wrong with my repo?

但我想知道为什么会发生这种情况?master 应该是更高级的分支吗?或者我的回购还有其他问题吗?

回答by Greg Franko

If you only want to clone the master branch, then run this command:

如果只想克隆 master 分支,请运行以下命令:

git clone [email protected]:**username**/ **Repository URL** -b master

Here is an example:

下面是一个例子:

git clone [email protected]:gfranko/jquery.selectBoxIt.js.git -b master

回答by VonC

1/ No, master is not necessary the most advanced branch. One can publish only to another branch, and then delete that branch...

1/ 不,master 不一定是最高级的分支。一个人只能发布到另一个分支,然后删除该分支...

2/ When that happen, you should select master as the default branch from the admin panel of the github repo, but that is not always possible. See this bug

2/ 发生这种情况时,您应该从 github 存储库的管理面板中选择 master 作为默认分支,但这并不总是可行的。看到这个错误

For anyone else who has hit this issue:

tekkub told me how to get around this bug via the freenode #github channel.

  • create a temporary branch,
  • push that to your repo,
  • select the default branch in the admin panel for that repo,
  • then delete the branch and push again.

Worked for us.

对于遇到此问题的任何其他人:

tekkub 告诉我如何通过 freenode #github 频道解决这个错误。

  • 创建一个临时分支,
  • 把它推送到你的仓库,
  • 在该存储库的管理面板中选择默认分支,
  • 然后删除分支并再次推送。

为我们工作。

(the idea is to temporary have twobranches, in order to be able to select master as default with the GUI admin panel, and then delete the extra branch)

(这个想法是临时有两个分支,以便能够在GUI管理面板中默认选择master,然后删除多余的分支)

回答by Mark Bessey

We had a similar issue with one of our repositories, though in our case, the github admin panel was showing "master" as the default branch, but checkouts were getting a different branch by default. Changing the default to one of the other branches, then back to "master" fixed our problem.

我们的一个存储库也有类似的问题,尽管在我们的例子中,github 管理面板将“master”显示为默认分支,但默认情况下结帐会获得不同的分支。将默认值更改为其他分支之一,然后返回“master”解决了我们的问题。