...
- When you do a
git pull
to get remote changes, if you have any local commits that haven't been pushed yet (wait, you're not working directly on master, are you?), specify--rebase
(you can also make this the default option as explained in this article). This will modify the sequence of commits to your local repository so that your locally-committed changes appear after those you just pulled. Now when you push your changes, your fellow committers will just see an incremental set of changes with yours at the end, and it will make sense to them. - Always fast-forward your branch commits to master. Fast-forward just means putting your commits at the end of the latest existing commits on a branch. When you run
git merge yourbranch
, by default, git will attempt to do a fast-forward commit if possible. It's not possible if there are any changes in master that aren't already in your branch. In this case, before attempting to merge your changes into master, switch to your branch and typegit rebase master
. This will put all the new commits from master in your branch, behind your changes. Now it should be possible to fast-forward merge your branch into master by switching to master and typinggit merge yourbranch
- Note: It's possible, though not common, that a
git pull --rebase
or agit rebase master
will fail due to a conflict. In that case, see this excellent article, which covers resolving rebase conflicts.
...