Git clone does not bring master branch

我与影子孤独终老i 提交于 2019-12-09 03:11:13

问题


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

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

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

And also I don't get a local master branch (git branch shows nothing).

I can fix the whole thing doing:

git checkout -b master origin/master

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


回答1:


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

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

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.

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




回答2:


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

git clone git@github.com:**username**/ **Repository URL** -b master

Here is an example:

git clone git@github.com:gfranko/jquery.selectBoxIt.js.git -b master



回答3:


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.



来源:https://stackoverflow.com/questions/2015530/git-clone-does-not-bring-master-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!