gitgit-rebase

Where does Git rebase make changes?


The Git documentation is not clear enough about this, yet everybody on the Internet seems to know it.

Say, I'm currently on a feature branch called feature/test. If I do git rebase master, where is the rebase performed? On the feature branch or on the master branch? I.e., which one is being changed? Does it have the same syntax as git merge in the way that the current branch is altered? In that case, would I have to go back to master and do a merge with my feature branch?

Edit: what I want to do is to "merge" (in this case rebase) the master branch into my feature branch, and then "merge" the feature branch back into master.


Solution

  • Since you rebase your feature/test on master the feature/test branch is changed. E.g.

               master
               |
               V
    A----B-----C
          \
           D----E
                ^
                |
                feature/test
    

    After doing

    git checkout feature/test
    git rebase master
    

    your repo will look like this

                master
                |
                V
     A----B-----C----D'----E'
                           ^
                           |
                           feature/test
    

    Note that D' != D, because it has a new parent now. Nevertheless it contains the same changes.

    EDIT:

    And how would I take the changes from feature/test back into master?

    Since feature/test is in line with master git will just fast forward the master branch.

    git checkout master
    git merge feature/test
    

    will result in

                           master
                           |
                           V
     A----B-----C----D'----E'
                           ^
                           |
                           feature/test
    

    See Git-Branching-Basic-Branching-and-Merging for details