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 ?
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 .
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 # ...
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.
Git pull rebase is a method of combining your local unpublished changes with the latest published changes on your remote.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With