Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't `git clone` clone all the branches? [duplicate]

Tags:

git

github

If I do

$ git clone https://github.com/dtu-compute/docker-mongodb
$ cd docker-mongodb
$ git branch
* master

but if you look at the Github branch page, there are two branches.

Question

Why don't I get all the branches with git clone?

like image 349
Jasmine Lognnes Avatar asked Jun 09 '16 15:06

Jasmine Lognnes


People also ask

Does git clone clones all branches?

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.

How do I clone a project with all branches?

To clone a branch in a git repository, start by cloning the master repository using the git clone command. Once complete, navigate into the repo directory. The command will show the branches that are available in the local repository.

How do I clone a git repository with multiple branches?

Use the --mirror Option to Clone All Branches in Git Create an empty directory and navigate to it. Clone your repository with the git clone --mirror command. The --mirror option sets up a mirror of the source repository with all branches.

Does git clone only one branch?

By default, the git clone command duplicates all the branches from a Git repository . To clone only a specific branch, you must use the –single-branch flag with the git commit command.


1 Answers

git branch only shows local branches by default; use git branch -r to see remote branches or git branch -a to see all. git clone only creates one local branch, master by default, which tracks (again, by default) the master branch on the remote repository.

like image 170
chepner Avatar answered Oct 14 '22 12:10

chepner