I have a master
and a development
branch, both pushed to GitHub. I've clone
d, pull
ed, and fetch
ed, but I remain unable to get anything other than the master
branch back.
I'm sure I'm missing something obvious, but I have read the manual and I'm getting no joy at all.
Cloning from a local repo will not work with git clone & git fetch: a lot of branches/tags will remain unfetched.
To get a clone with all branches and tags.
To get a clone with all branches and tags but also with a working copy:
This Bash script helped me out:
It will create tracking branches for all remote branches, except master (which you probably got from the original clone command). I think you might still need to do a
to be sure.
You only need to use "git clone" to get all branches.
Even though you only see master branch, you can use "git branch -a" to see all branches.
And you can switch to any branch which you already have.
Don't worry that after you "git clone", you don't need to connect with the remote repo, "git branch -a" and "git checkout " can be run successfully when you close your wifi. So it is proved that when you do "git clone", it already has copied all branches from the remote repo. After that, you don't need the remote repo, your local already has all branches' codes.
Here is another short one-liner command which creates local branches for all remote branches:
It works also properly if tracking local branches are already created. You can call it after the first
git clone
or any time later.If you do not need to have
master
branch checked out after cloning, useI wrote this small Powershell functions to be able to checkout all my git branches, that are on origin remote.
More git functions can be found on my git settings repo
First, clone a remote Git repository and cd into it:
Next, look at the local branches in your repository:
But there are other branches hiding in your repository! You can see these using the
-a
flag:If you just want to take a quick peek at an upstream branch, you can check it out directly:
But if you want to work on that branch, you'll need to create a local tracking branch which is done automatically by:
and you will see
That last line throws some people: "New branch" - huh? What it really means is that the branch is taken from the index and created locally for you. The previous line is actually more informative as it tells you that the branch is being set up to track the remote branch, which usually means the origin/branch_name branch
Now, if you look at your local branches, this is what you'll see:
You can actually track more than one remote repository using
git remote
.At this point, things are getting pretty crazy, so run
gitk
to see what's going on: