Another question said git pull
is like a git fetch
+ git merge
.
But what is the difference between git pull
VS git fetch
+ git rebase
?
Another question said git pull
is like a git fetch
+ git merge
.
But what is the difference between git pull
VS git fetch
+ git rebase
?
In reply to your first statement 'git pull is like a git fetch + git merge.',
(Ref: https://git-scm.com/docs/git-pull)
For your second statement/question: 'But what is the difference between git pull VS git fetch + git rebase' Again, from same source:
Now, if you wanted to ask the difference between fetch and merge, that is answered here too: https://git-scm.com/book/en/v2/Git-Branching-Rebasing (the difference between altering the way version history is recorded and what not)
It should be pretty obvious from your question that you're actually just asking about the difference between
git merge
andgit rebase
.So let's suppose you're in the common case - you've done some work on your master branch, and you pull from origin's, which also has done some work. After the fetch, things look like this:
If you merge at this point (the default behavior of git pull), assuming there aren't any conflicts, you end up with this:
If on the other hand you did the appropriate rebase, you'd end up with this:
The content of your work tree should end up the same in both cases; you've just created a different history leading up to it. The rebase rewrites your history, making it look as if you had committed on top of origin's new master branch (
R
), instead of where you originally committed (H
). You should never use the rebase approach if someone else has already pulled from your master branch.Finally, note that you can actually set up
git pull
for a given branch to use rebase instead of merge by setting the config parameterbranch.<name>.rebase
to true. You can also do this for a single pull usinggit pull --rebase
.