git pull --rebase -- is the remote rebased onto the local branch?

Viewed 104

I have been reviewing some Git basics and in this Atlassian documentation about pulling, merging and rebasing there is one thing I don't really understand. The base state of the branches is like this (there are actual images on the page, I can't post them with my reputation):

                         A - B - C (Master on remote origin)
                       / 
(Local origin/master) D - E - F - G (Local master)

Now we want to pull changes from the remote and rebase them. I would have expected, from reading other documentation and playing around with rebase, that git pull --rebase would replay the commits E-F-G on top of A-B-C. But instead the Atlassian tutorial says the result looks like that:

                         A - B - C (Master on remote origin)
                       / 
(Local origin/master) D - E - F - G  -  A - B - C (Local master)

So the remote changes got rebased onto the local branch. I didn't think it worked like that (at least not without special commands) and it also seems more invasive than the alternative. If you were to push now, you'd rewrite lots of the remote's history after all.

Is the documentation correct here and in which cases does it happen like that? Most descriptions seem to imply or show that the remote branch is fetched and your local one rebased on top of it, which also seems to make the most sense.

I guess I must be misunderstanding something or I'm misreading the figures.

1 Answers

You're absolutely right, that tutorial is incorrect. What you expected (and observed) is what git pull --rebase does. The Git documentation says in man git-pull:

-r
--rebase[=false|true|merges|preserve|interactive]

When true, rebase the current branch on top of the upstream branch after fetching. If there is a remote-tracking branch corresponding to the upstream branch and the upstream branch was rebased since last fetched, the rebase uses that information to avoid rebasing non-local changes.

With current branch they're referring to the locally checked-out branch, with upstream branch they're referring to the remote branch. Note that --rebase is equivalent to --rebase=true.

Related