I understand that the difference between git rebase and git merge is that git rebase moves the beginning of a branch to the tip of another branch, where as git merge creates a new commit that represents (i.e. includes or integrates) branched commits from another branch. So for example:
Since git pull is equivalent to git fetch + git merge, and git pull --rebase is equivalent to git fetch + git rebase, let's say you have a local master branch and a remote master branch:
- o - o - o - H - A - B - C (master)
\
P - Q - R (origin/master)
HEAD is at C
If you git pull you end up with this:
- o - o - o - H - A - B - C - X (master)
\ /
P - Q - R --- (origin/master)
HEAD will now be at X which is commit R of the remote repository's commit history because the merge commit (X) represents (i.e. includes or integrates) the remote branch's commit history that was merged
If on the other hand you did git pull --rebase, you would end up with this:
- o - o - o - H - P - Q - R - A' - B' - C' (master)
|
(origin/master)
As you can see git pull is not the same as git pull --rebase because git pull --rebase gives HEAD at C' which is commit C of the local master branch, where as when git pull was used HEAD was at R. In other words, contents of the commit history via git pull are the same as the contents of the commit history from git pull --rebase, but the order of commits in the commit histories is different
But what happens when you are pulling from a remote branch when no work has been done on the local master branch:
local master branch and a remote master branch:
- o - o - o - H (master)
\
P - Q - R (origin/master)
HEAD is at H
If you git pull you end up with this:
- o - o - o - H - X (master)
\ \
P - Q - R --- (origin/master)
HEAD will now be at X which is commit R of the repo because the merge commit represents the remote branch that was merged
If on the other hand you did git pull --rebase, would you end up with this?:
- o - o - o - H - P - Q - R (master)
|
(origin/master)
Meaning that HEAD is at R which means that git pull --rebase is the same as git pull when no work is done on the local branch