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.
If refs/heads/master can be fast-forwarded to refs/remotes/foo/master, the output of
should return the SHA1 id that refs/heads/master points to. With this, you can put together a script that automatically updates all local branches that have had no diverting commits applied to them.
This little shell script (I called it git-can-ff) illustrates how it can be done.
As of git 2.9:
git pull --rebase --autostash
See https://git-scm.com/docs/git-rebase
It can be done using below script... It will first fetch all branches and checkout one by one and update by itself.
This still isn't automatic, as I wish there was an option for - and there should be some checking to make sure that this can only happen for fast-forward updates (which is why manually doing a pull is far safer!!), but caveats aside you can:
to update the position of your local branch without having to check it out.
Note: you will be losing your current branch position and moving it to where the origin's branch is, which means that if you need to merge you will lose data!
A script I wrote for my GitBash. Accomplishes the following:
git checkout branch
git pull origin
** I use this but have not tested thoroughly, use at own risk. See an example of this script in a .bash_alias file here.
The script from @larsmans, a bit improved:
This, after it finishes, leaves working copy checked out from the same branch as it was before the script was called.
The
git pull
version: