I have been taught to rebase my the repo before starting my work on any branch. But I am confused in
git pull --rebase
and git rebase <branch>
. What is the difference between the two?
Asked
Active
Viewed 146 times
1

Pravin
- 1,671
- 5
- 23
- 36
1 Answers
2
Exactly as the commands suggest, one does a pull and a rebase, and uses the current branch's default upstream. The other only does a rebase, and uses the specified branch (which is not necessarily the current branch's upstream).
This means the first one fetches all the new commits from upstream, then rolls back local commits, fast-forwards to the upstream head, then re-applies the local commits.
The second one doesn't fetch anything, it rebases the current branch on top of the specified branch without checking to see if that branch has been updated.
The git help rebase
and git help pull
documentation describes these pretty well, you should read them.

Jonathan Wakely
- 166,810
- 27
- 341
- 521
-
2Technically, one does a _fetch_ and a rebase. – Michał Politowski Jan 22 '15 at 13:09
-
I never use rebase outside of the purpose of the interactive mode to rename, squash, or delete local commits. Suppose I am working on a local branch that is out of sync with the mainline, then what would be the real purpose for me to use git rebase in favour of git pull --rebase? I have former colleagues who simply use git rebase whenever they want to push to origin/mainline. I'd assume merge conflicts are still detected, but I'd assume they would be missing the step of testing the merged changes since the local is not synced with a pull – user1836155 Oct 21 '15 at 20:56
-
@user1836155 Note: git 2.8 (March 2016) will allow for a `git pull --rebase=interactive command`. See http://stackoverflow.com/a/29717607/6309. – VonC Jan 27 '16 at 09:39