I cloned a Git repository, which contains about five branches. However, when I do git branch
I only see one of them:
$ git branch
* master
I know that I can do git branch -a
to see all the branches, but how would I pull all the branches locally so when I do git branch
, it shows the following?
$ git branch
* master
* staging
* etc...
Now locally your
yourNewLocalBranchName
is yourrequiredRemoteBranch
.You can fetch all the branches by:
or:
The
--depth=10000
parameter may help if you've shallowed repository.To pull all the branches, use:
If above won't work, then precede the above command with:
as the
remote.origin.fetch
could support only a specific branch while fetching, especially when you cloned your repo with--single-branch
. Check this by:git config remote.origin.fetch
.After that you should be able to checkout any branch.
See also:
To push all the branches to the remote, use:
eventually
--mirror
to mirror all refs.If your goal is to duplicate a repository, see: Duplicating a repository article at GitHub.
If you are here seeking a solution to get all branches and then migrate everything to another Git server, I put together the below process. If you just want to get all the branches updated locally, stop at the first empty line.
Looping didn't seem to work for me and I wanted to ignore origin/master. Here's what worked for me.
After that:
If you do:
then they will be all there locally. If you then perform:
you'll see them listed as remotes/origin/branch-name. Since they are there locally you can do whatever you please with them. For example:
or
or
To list remote branches:
git branch -r
You can check them out as local branches with:
git checkout -b LocalName origin/remotebranchname