1

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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Technically, one does a fetch and a rebase.
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 Note: git 2.8 (March 2016) will allow for a git pull --rebase=interactive command. See stackoverflow.com/a/29717607/6309.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.