Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can "git pull --all" update all my local branches?

Tags:

git

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.

like image 219
mpoisot Avatar asked Nov 30 '10 20:11

mpoisot


People also ask

Does git pull update all my local branches?

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.

Does git pull pull all branches?

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

Does git pull update local repository?

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.


2 Answers

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.

like image 57
John Avatar answered Oct 11 '22 14:10

John


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.

like image 27
Cascabel Avatar answered Oct 11 '22 12:10

Cascabel