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.
git fetch. On its own, git fetch updates all the remote tracking branches in local repository. No changes are actually reflected on any of the local working branches.
git pull fetches updates for all local branches, which track remote branches, and then merges the current branch.
The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content.
I use the sync
subcommand of hub to automate this. I have alias git=hub
in my .bash_profile
, so the command I type is:
git sync
This updates all local branches that have a matching upstream branch. From the man page:
- If the local branch is outdated, fast-forward it;
- If the local branch contains unpushed work, warn about it;
- If the branch seems merged and its upstream branch was deleted, delete it.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With