Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between git pull --rebase and git pull --ff-only

Let's say origin/master has commit A--B--C and my local/master has commit A--B--D.

What will happen if I use git pull --rebase ?

What will happen if I use git pull --ff-only ?

Is there any difference in the resulting commit tree ?

like image 335
Nico Avatar asked Aug 21 '14 15:08

Nico


People also ask

Is git pull rebase same as git pull?

This two git commands are not interchangeable. Git pull downloads the newest changes from the remote repository and applies the changes to your local repository. Generally, git pull is git fetch and git merge. Rebasing on the other hand can be a replacement for git merge .

What does git pull ff only do?

With git pull --ff-only , Git will update your branch only if it can be “fast-forwarded” without creating new commits. If this can't be done (if local and remote have diverged), git pull --ff-only simply aborts with an error message: $ git pull --ff-only upstream master # ...

Is git pull rebase better?

It is best practice to always rebase your local commits when you pull before pushing them. As nobody knows your commits yet, nobody will be confused when they are rebased but the additional commit of a merge would be unnecessarily confusing.

What is git pull and rebase?

Git pull rebase is a method of combining your local unpublished changes with the latest published changes on your remote.


1 Answers

What will happen if I use git pull --rebase ?

git pull --rebase is roughly equivalent to

git fetch git rebase origin/master 

i.e. your remote changes (C) will be applied before the local changes (D), resulting in the following tree

A -- B -- C -- D 

What will happen if I use git pull --ff-only ?

It will fail.

git pull --ff-only corresponds to

git fetch git merge --ff-only origin/master 

--ff-only applies the remote changes only if they can be fast-forwarded. From the man:

Refuse to merge and exit with a non-zero status unless the current HEAD is already up-to-date or the merge can be resolved as a fast-forward

Since your local and remote branches have diverged, they cannot be resolved by a fast-forward and git pull --ff-only would fail.

like image 100
Gabriele Petronella Avatar answered Oct 10 '22 08:10

Gabriele Petronella