find and solve || findandsolve.com
Please wait.....

Welcome back.






Before Read Terms of use

How to Fetch all Git Branches

I have cloned a Git repository, which contains about three 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...


Answer


Option 1.


For tracking all remote branches run this command.

 for remote in `git branch -r`; do git branch --track ${remote#origin/} $remote; done

You can fetch all branches from all remotes like as given below:

git fetch --all

fetch: it will not update local branches only track remote branches.if you want to update your local branches you still need to pull every branch.

fetch: If you want to list all remote branches:

 git branch -a

If you wan to update local branches which track remote branches 

git pull --all


Option 2.


This assumes all branches are tracked.

$ git remote update

$ git pull --all

If they aren't you can fire this in Bash:

for remote in `git branch -r `; do git branch --track $remote; done



Option 3.


List  of remote branches by given below code

git branch -r

You can check them out as local branches like as given below code:

git checkout -b LocalName origin/remotebranchname


Mahira  khanna

Mahira khanna

I have the skills you need for you company blog, website, or other content materials

Comments



Report Response