pull vs fetch:
The way I understand this, is that git pull
is simply a git fetch
followed by git merge
. I.e. you fetch the changes from a remote branch and then merge it into the current branch.
merge vs rebase:
A merge will do as the command says; merge the differences between current branch and the specified branch (into the current branch). I.e. the command git merge another_branch
will the merge another_branch
into the current branch.
A rebase works a bit differently and is kind of cool. Let's say you perform the command git rebase another_branch
. Git will first find the latest common version between the current branch and another_branch
. I.e. the point before the branches diverged. Then git will move this divergent point to the head of the another_branch
. Finally, all the commits in the current branch since the original divergent point are replayed from the new divergent point. This creates a very clean history, with fewer branches and merges.
However, it is not without pitfalls! Since the version history is "rewritten", you should only do this if the commits only exists in your local git repo. That is: Never do this if you have pushed the commits to a remote repo.
The explanation on rebasing given in this online book is quite good, with easy-to-understand illustrations.
pull with rebasing instead of merge
I'm actually using rebase quite a lot, but usually it is in combination with pull:
git pull --rebase
will fetch remote changes and then rebase instead of merge. I.e. it will replay all your local commits from the last time you performed a pull. I find this much cleaner than doing a normal pull with merging, which will create an extra commit with the merges.