Another question says that git pull is like a git fetch + git merge.
But what is the difference between git pull and git fetch + git rebase?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It should be pretty obvious from your question that you’re actually just asking about the difference between
git mergeandgit 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 pullfor a given branch to use rebase instead of merge by setting the config parameterbranch.<name>.rebaseto true. You can also do this for a single pull usinggit pull --rebase.