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.
This issue is not solved (yet), at least not easily / without scripting: see this post on git mailing list by Junio C Hamano explaining situation and providing call for a simple solution.
The major reasoning is that you shouldn't need this:
The call for a solution was for an option or external script to prune local branches that follow now remote-tracking branches, rather than to keep them up-to-date by fast-forwarding, like original poster requested.
Note: as of git 2.10 no such solution exists. Note that the
git remote prune
subcommand, andgit fetch --prune
are about removing remote-tracking branch for branch that no longer exists on remote, not about removing local branch that tracks remote-tracking branch (for which remote-tracking branch is upstream branch).If you're on Windows you can use PyGitUp which is a clone of
git-up
for Python. You can install it using pip withpip install --user git-up
or through Scoop usingscoop install git-up
[
There are a lot of answers here but none that use
git-fetch
to update the local ref directly, which is a lot simpler than checking out branches, and safer thangit-update-ref
.Here we use
git-fetch
to update non-current branches andgit pull --ff-only
for the current branch. It:and here it is:
From the manpage for
git-fetch
:By specifying
git fetch <remote> <ref>:<ref>
(without any+
) we get a fetch that updates the local ref only when it can be fast-forwarded.Note: this assumes the local and remote branches are named the same (and that you want to track all branches), it should really use information about which local branches you have and what they are set up to track.
The behavior you describe for
pull --all
is exactly as expected, though not necessarily useful. The option is passed along to git fetch, which then fetches all refs from all remotes, instead of just the needed one;pull
then merges (or in your case, rebases) the appropriate single branch.If you want to check out other branches, you're going to have to check them out. And yes, merging (and rebasing) absolutely require a work tree, so they cannot be done without checking out the other branches. You could wrap up your described steps into a script/alias if you like, though I'd suggest joining the commands with
&&
so that should one of them fail, it won't try to plow on.It looks like many others have contributed similar solutions, but I thought I'd share what I came up with and invite others to contribute. This solution has a nice colorful output, gracefully handles your current working directory, and is fast because it doesn't do any checkouts, and leaves your working directory in tact. Also, it is just a shell script with no dependencies other than git. (only tested on OSX so far)
https://github.com/davestimpert/gitup
Sorry I also seem to have come up with the same name as the other tool above.
I use the
sync
subcommand of hub to automate this. Hub is aliased asgit
, so the command I type is:This updates all local branches that have a matching upstream branch. From the man page:
It also handles stashing/unstashing uncommitted changes on the current branch.
I used to use a similar tool called git-up, but it's no longer maintained, and
git sync
does almost exactly the same thing.