Search code examples
gitgit-mergegit-rebasegit-pull

Running `git pull --rebase`, what does it rebase against?


I see a lot of examples of:

git pull --rebase

but I am left wondering what branch is merged into the current branch. Shouldn't it be git pull --rebase <master> or git pull --rebase <dev>?


Solution

  • It first fetches origin/theBranch, then rebases your changes on top of origin/theBranch.


    With a sketch :

    • before git pull --rebase :

      *--*--*--*--A <- origin/theBranch
                   \
                    M--Y <- theBranch   # your local branch
      
    • git pull --rebase step 1 : git fetch

      *--*--*--*--A--B--C--D <- origin/theBranch
                   \
                    M--Y <- theBranch
      
    • git pull --rebase step 2 : git rebase origin/theBranch

      *--*--*--*--A--B--C--D <- origin/theBranch
                            \
                             M'--Y' <- theBranch