Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only master branch is visible after cloning a Git repo

Tags:

git

I am working on a project and I created a repository with a master branch. Someone who is working on it added a branch named new-branch -- their code changes are in this branch.

However, when I clone the repository:

$ git clone [email protected]:me/my-repo.git

I can clone it successfully, but it only shows the master branch. I do not know how I can view/get the new-branch.

How would I pull this branch to my repository?

like image 791
David542 Avatar asked Jan 17 '12 04:01

David542


People also ask

Does git clone only clones master branch?

The classic git clone command with the --single-branch option will clone only the master branch by default. If you want to clone another branch, you should add the --branch flag with the name of the desired branch.

Does cloning a repo clone all branches?

The idea is to use the git-clone to clone the repository. This will automatically fetch all the branches and tags in the cloned repository. To check out the specific branch, you can use the git-checkout command to create a local tracking branch.

Why git clone is not working?

If you have a problem cloning a repository, or using it once it has been created, check the following: Ensure that the user has gone through initial GitCentric login and has the correct username, email, and ssh. This should return a usage message that refers to the config-branch, config-repo, and ls-repo commands.


1 Answers

When you clone a repository, all remote branches are created as "remote tracking branches" in your repository. These aren't shown by default, but you can see these with:

git branch -a

If you do a git checkout new-branch, git will find the remote tracking branch of the same name, automatically create a new local branch from the same commit, and switch to the new local branch.

For future work, the git fetch command will update all the remote tracking branches with their latest commit from the remote.

like image 151
Greg Hewgill Avatar answered Sep 21 '22 23:09

Greg Hewgill