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?

Eimantas
  • 48,927
  • 17
  • 132
  • 168
Pablo Fernandez
  • 103,170
  • 56
  • 192
  • 232
  • @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. – VonC Jan 06 '10 at 20:58
  • @Elimnatas Why did you edit my question like that? – Pablo Fernandez Jan 06 '10 at 21:01
  • @Pablo: allegedly because of http://meta.stackexchange.com/questions/2950/should-hi-thanks-and-taglines-and-salutations-be-removed-from-posts , but you can roll back that edit if you want. – VonC Jan 06 '10 at 21:16
  • We are getting machine-like people! It gives me the creeps :S – Pablo Fernandez Jan 06 '10 at 21:28

3 Answers3

11

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
Greg Franko
  • 1,780
  • 15
  • 14
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)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 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 issue – Pablo Fernandez Jan 06 '10 at 20:44
  • @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. – VonC Jan 06 '10 at 20:58
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.

Mark Bessey
  • 19,598
  • 4
  • 47
  • 69