Take the 2-minute tour ×

I have a git repo in GitHub. I've been mostly using git gui to manage it up to now, but now I'm starting to use the shell. What I want to know is, how do I fetch all the branches in a remote and merge them into the respective branches on my local repo automatically? For example, if I have branches master and development, and thus origin/master and origin/development, I want to fetch origin/master and merge it into master and to fetch origin/development and merge it into development.

Is there a command that does this?

share|improve this question

4 Answers 4

up vote 1 down vote accepted

To list the local branches:

$ git branch
*  master

To list available remote branches:

$ git branch -r
* master

Now it gets interesting, To track a remote branch1:

$ git branch --track branch1

This enables a pull to also update the branch locally.

Simply switch to the new branch with:

$ git checkout branch1

By using the --track parameter, the remote branches are added to .git/config and will become persistent. ie this only needs to be done once. The pertinent entries from .git/config will show like this:


By running branch --track commands for each of the remote branches you would like to have locally will do exactly what you want.

share|improve this answer

There isn't a single command that will fetch and merge all branches simultaneously. The git pull command:


So it only works on the current branch. This is necessary because you need to be in a position to deal with conflicts when they arise.

share|improve this answer

If you know the branch names in question, you can set this up so it happens on a

git pull

by editing the .git/config file.


man git-pull

for more details: (cloned from man git-pull below)

   o   Command line pull of multiple branches from one repository:

           $ git checkout master
           $ git fetch origin +pu:pu maint:tmp
           $ git pull . tmp

       local repository by fetching from the branches (respectively) pu
       and maint from the remote repository.

       the others will not be.
share|improve this answer
You can do that for a git push, but can you do the same for a git pull? –  Greg Hewgill Sep 28 '09 at 0:02
Sort of. You can tell it to fetch and update all remote tracking branches, and pull the current branch. The other branches you have will need to be manually merged. Note that a pull on a branch branched from a remote tracking branch will merge from the remote tracking branch. –  Alex Brown Sep 28 '09 at 0:07
And the man page claims you can do the real deal, too. I've updated the post. –  Alex Brown Sep 28 '09 at 0:10

Put the following in a file named pull-all:

git fetch origin
git checkout development
git merge origin/development
git checkout master
git merge origin/master

Then, give pull-all executable permissions and put it into a directory on your path. Usually, $HOME/bin:

chmod +x pull-all
mv pull-all $HOME/bin
share|improve this answer
This may need manual intervention if there are any conflicts in the merge that cannot be automatically resolved. –  Greg Hewgill Sep 28 '09 at 0:17
Problem with this is I will have to modify this every time I add new branches. –  Ram Rachum Sep 28 '09 at 0:28

Your Answer


