Git's default behaviour when running the pull
command is to merge the remote branch into the tracking branch. This gives a lot of merge commits in the history that provide no information and just clutter the history. Here's an example of what I found in a repository:
You can change this behaviour by adding the --rebase flag to git pull
:
git pull --rebase
This rebases the tracking branch on the remote branch. It's more convenient to change the default so you don't have to add this flag every time you do a pull. To do this, run:
git config --global branch.autosetuprebase always
If you have already cloned a repository, this will have no effect on that repo.
You'll have to edit the .git/config
file in the repo to have the rebase setting for all tracking branches set to true, e.g.:
[branch "master"]
remote = origin
merge = refs/heads/master
rebase = true
After this, you only need to make sure that everyone else in your team has those settings too, so you don't have to see every pull they did in your history.
EDIT Febrary 16, 2015: I had written that branch.autosetuprebase
should be set to true
. I'm not sure if that was a mistake
or if it worked in earlier Git versions. Anyway, it should be set to always
.