I've set up tracking branches with the --track
option, and when I do a git pull
on master
, it fetches all branches to origin/branchname
but doesn't merge with the local tracking branches. This is extra annoying, because if I later do a git push
on master
, it says that non-fast-forward updates were rejected on the tracking branches, since they weren't fast-forwarded on the initial git pull
.
My question is: How do I make it so that git pull
with fetch all branches and automatically fast-forward all the tracking branches?
Note: git pull
used to fast-forward all my tracking branches with my GitHub repos, but now that I've set up my own repos using Gitolite, this problem is cropping up.
SmartGit, for example, has an option to automatically merge changes from the tracked branch if you switch to a branch. This should do what you want to achieve.
But wait:
git pull
after thefetch
part) files unless the branch is checked out first. See "Can “git pull --all
” update all my local branches?"git pull
onmaster
will merge files onmaster
, meaning the next push will be a fast-forward one. A non fast-forward can only occur if a push to the remotemaster
from another repo has been done prior to your push.Note: I suppose you have tracked all your remote branches as in "Track all remote git branches as local branches."
Note: Git 2.0 (Q2 2014) will introduce with commit b814da8 a config push.ff:
If you really want to fast forward all local branches that are tracking remote branches you might want to consider adding this as an alias to your
~/.gitconfig
:You can then run
git pull-all
, it will iterate through your local branches and run agit pull --ff-only
on each.Shell script that fast-forwards all branches that have their upstream branch set to the matching origin/ branch without doing any checkouts
it doesn't change your current branch at any time, no need to deal with working copy changes and time lost checking out
it only does fast-forwards, branches that cannot be fast-forwarded will show an error message and will be skipped
Make sure all your branches' upstream branches are set correctly by running
git branch -vv
. Set the upstream branch withgit branch -u origin/yourbanchname
Copy-paste into a file and chmod 755: