I often have at least 3 remote branches: master, staging and production. I have 3 local branches that track those remote branches.
Updating all my local branches is tedious:
git fetch --all
git rebase origin/master
git checkout staging
git rebase origin/staging
git checkout production
git rebase origin/production
I'd love to be able to just do a "git pull -all", but I haven't been able to get it to work. It seems to do a "fetch --all", then updates (fast forward or merges) the current working branch, but not the other local branches.
I'm still stuck manually switching to each local branch and updating.
Note: Even though I posted my own solution, I would recommend using git-up, which is also the accepted answer.
I know this question is almost 3 years old, but I asked myself the very same question and did not found any ready made solution. So, I created a custom git command shell script my self.
Here it goes, the
git-ffwd-update
script does the following...git remote update
to fetch the lates revsgit remote show
to get a list of local branches that track a remote branch (e.g. branches that can be used withgit pull
)git rev-list --count <REMOTE_BRANCH>..<LOCAL_BRANCH>
how many commit the local branch is behind the remote (and ahead vice versa)git branch -l -f <LOCAL_BRANCH> -t <REMOTE_BRANCH>
the script can be called like:
The full script, should be saved as
git-ffwd-update
and needs to be on thePATH
.There are plenty of acceptable answers here, but some of the plumbing may be be a little opaque to the uninitiated. Here's a much simpler example that can easily be customized:
If you add
~/bin/git
to yourPATH
(assuming the file is~/bin/git/git-update-all
), you can just run:Here is a good answer: How to fetch all git branches
Add this script to
.profile
on Mac OS X:To complete the answer by Matt Connolly, this is a safer way to update local branch references that can be fast-forwarded, without checking out the branch. It does not update branches that cannot be fast-forwarded (i.e. that have diverged), and it does not update the branch that is currently checked out (because then the working copy should be updated as well).
It's not so hard to automate: