Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git clone does not bring master branch

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?

like image 583
Pablo Fernandez Avatar asked Jan 06 '10 19:01

Pablo Fernandez


People also ask

Does git clone clone the master branch?

While you can clone repositories with the git clone command, keep in mind that this clones the branch and the remote HEAD . This is usually master by default and includes all other branches in the repository. So when you clone a repository, you clone the master and all other branches.

Why does GitHub not show master branch?

If you didn't push master to GitHub, you can't see master branch on GitHub. I assumed you created Tutorial repo from bash, not from GitHub. master branch is automatically created by Git on a new repository but not pushed. To get the branch on GitHub do git push origin master:master .

How do I get the master branch back in git?

In order to switch to the master branch, on this specific commit, we are going to execute the “git checkout” command and specify the “master” branch as well as the commit SHA. In order to check that you are correctly on a specific commit, you can use the “git log” command again.


2 Answers

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
like image 104
Greg Franko Avatar answered Oct 11 '22 16:10

Greg Franko


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)

like image 23
VonC Avatar answered Oct 11 '22 16:10

VonC