Git clone does not bring master branch
Asked Answered
W

3

7

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?

Winery answered 6/1, 2010 at 19:20 Comment(4)
@Pablo: why: because you delete a remote branch on which you had push some commits (and not on the remote master). The GitHub part is only related to their admin console, displaying that deleted remote branch as the default, and preventing the user to change the default branch to master. That bit is a GUI issue, not a Git issue.Kauai
@Elimnatas Why did you edit my question like that?Winery
@Pablo: allegedly because of meta.stackexchange.com/questions/2950/… , but you can roll back that edit if you want.Kauai
We are getting machine-like people! It gives me the creeps :SWinery
K
8

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)

Kauai answered 6/1, 2010 at 19:26 Comment(2)
Ok. That's a solution to the problem and thanks for that. But I wanted to know why that happens. Or at least to know if it's a github thing instead of a git issueWinery
@Pablo: why: because you delete a remote branch on which you had push some commits (and not on the remote master). The GitHub part is only related to their admin console, displaying that deleted remote branch as the default, and preventing the user to change the default branch to master. That bit is a GUI issue, not a Git issue.Kauai
M
11

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

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

Here is an example:

git clone [email protected]:gfranko/jquery.selectBoxIt.js.git -b master
Merta answered 26/4, 2012 at 16:19 Comment(0)
K
8

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)

Kauai answered 6/1, 2010 at 19:26 Comment(2)
Ok. That's a solution to the problem and thanks for that. But I wanted to know why that happens. Or at least to know if it's a github thing instead of a git issueWinery
@Pablo: why: because you delete a remote branch on which you had push some commits (and not on the remote master). The GitHub part is only related to their admin console, displaying that deleted remote branch as the default, and preventing the user to change the default branch to master. That bit is a GUI issue, not a Git issue.Kauai
P
1

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.

Ptisan answered 25/4, 2013 at 20:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.