Eduard Luca
Eduard Luca

Reputation: 6602

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? Ie. 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.

Upvotes: 4

Views: 35

Answers (1)

René Link
René Link

Reputation: 51343

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

Upvotes: 4

Related Questions