Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to clone whole Github repository (all branches)

Autumnmist October 5, 2013

I fully admit I am new to Git (I used Github's Mac GUI client for a year and recently decided to get a little more advanced by using SourceTree), but I'm confused about SourceTree's behavior when I freshly clone a repository from Github. The Github repository has multiple branches. When I used GitHub for Mac GUI to clone a repository with multiple branches, the entire repository and all its various branches would get cloned to my local machine.

However when I use SourceTree to clone a repository from Github, SourceTree only clones the single branch that I list in the clone dialog. Is this expected behavior or is Github for Mac's behavior the "expected" way? How can I make SourceTree clone the entire repository and all its branches to my local machine?

1 answer

1 accepted

3 votes
Answer accepted
Jeff Thomas
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 6, 2013

When you clone a Git repository, you have access to all of the remote branches and the full repository, you'll just need to checkout the appropriate branch. By default SourceTree checks out only the default branch during a clone. You'll need to checkout the remote branch and have it track locally.

In SourceTree if you want to checkout one of these remote branches, look for the branch on the left-hand side under remotes. You can then right-click on a branch and select checkout.

Autumnmist October 6, 2013

Thanks, but does that mean there's no way to checkout all the branches at once?

Like deep.pancholi likes this
Jeff Thomas
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 6, 2013

You can only checkout one branch at a time in Git. A checkout in Git updates your local files to the state of that commit/branch.

You still have access to all the branches of the remote repository through the remotes menu on the left. You can create a remote-tracking branch by right-clicking on any of them and selecting checkout. Once you do that, the branch will appear under the local menu on the left. I haven't been able to find a way to do this in bulk.

So, by doing the clone, you do have access to all of the branches from the GitHub repository. Does that help with what you're trying to accomplish?

Like Wojt likes this
Autumnmist October 7, 2013

Yes I think so! I'm slightly still confused because when I cloned a repository using the GitHub Mac GUI, all of the remote branches would appear (in some way) on my local machine so that I could switch between them when my local machine was not online (e.g. while flying). I guess maybe GitHub Mac was automatically creating remote-tracking branches on my local machine for every branch in the remote?

If I'm understanding you properly, it sounds like after cloning a new repository, I should create remote-tracking branches for each remot branch I might want to access offline.

Jeff Thomas
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 7, 2013

I haven't used the GitHub Mac GUI so I'm not sure what it was doing, but in SourceTree you should still have access to the Remotes section on the left-hand side and be able to checkout remote branches even while offline (at least it appeared to work when I disconnected my network).

I don't think you should have to create remote-tracking branches ahead of time.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events