Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git pull all branches from remote repository

How do I pull all of the remote branches to my own repository?

if I type:

git branch -a 

I get a long list of branches, but if I type:

git branch  

I see only 2 of them.

How do I pull ALL branches into my local list?

I know I can do:

git checkout --track origin/branch-name 

but that pulls and checks out only one branch at a time. Any way to get it all done at once without that whole tedious work of running git checkout --track origin/branch-name over and over and over again?


ps. I tried following commands, none of them made remote branches appear in my git branch list:

git fetch --all git remote update git pull --all 
like image 241
MarcinWolny Avatar asked Sep 19 '13 10:09

MarcinWolny


People also ask

Does git pull pull all branches?

git pull fetches updates for all local branches, which track remote branches, and then merges the current branch.

How do I pull everything in git?

To get all the changes from all the branches, use git fetch --all . And if you'd like to clean up some of the branches that no longer exist in the remote repository, git fetch --all --prune will do the cleaning up!


1 Answers

The command I usually use to make all visible upstream branches, and tracking them is detailed in "Track all remote git branches as local branches":

remote=origin ; for brname in `git branch -r | grep $remote | grep -v master | grep -v HEAD | awk '{gsub(/[^\/]+\//,"",$1); print $1}'`; do git branch --set-upstream-to $remote/$brname $brname ; done 

Or:

remote=origin ; for brname in `git branch -r | grep $remote | grep -v master | grep -v HEAD | awk '{gsub(/[^\/]+\//,"",$1); print $1}'`; do git branch --track $brname $remote/$brname  ; done 

For more readability:

remote=origin ; // put here the name of the remote you want for brname in `   git branch -r | grep $remote | grep -v master | grep -v HEAD    | awk '{gsub(/[^\/]+\//,"",$1); print $1}' `; do    git branch --set-upstream-to $remote/$brname $brname;    # or   git branch --track $brname  $remote/$brname ;  done 

The second one is for creating new local branches tracking remote branches.

like image 52
VonC Avatar answered Oct 06 '22 12:10

VonC