Search code examples
gitrebase

Git rebase returns but nothing happens


I am trying to rebase my feature branch onto develop (git rebase develop after checking out the branch) but every time I try I just get the message:
Current branch feature/my-feature-branch is up to date
but checking out develop reveals that nothing has changed from the git log.
Would appreciate any pointers, thanks.


Solution

  • There seems to be a misunderstanding here.

    If you rebase a feature branch on top of develop, nothing will happen to develop.

    So checking out develop afterwards will correctly show you that nothing changed. This is expected. Rebasing does not change the branch you rebase on top of.

    Instead it may change the branch you are rebasing, in this case your feature branch.

    Let's give an example, starting with this:

                     develop
                        v
    1---2---3---4---5---6
             \
              7---8---9
                      ^
                   feature
    

    if you now check out the feature branch and rebase it on top of develop, you end up with this:

    git checkout feature
    git rebase develop
    
                     develop
                        v
    1---2---3---4---5---6
                         \
                          7'--8'--9'
                                  ^
                               feature
    

    but note that nothing happened to develop.

    I marked the 7-8-9 commits with an apostrophe to show that these are actually new commits, they will be created from the original 7-8-9 commits but they will have new parents and thus new hashes.

    The git message you got, Current branch feature/my-feature-branch is up to date means you were already in that last situation when you executed your rebase commands. Your feature branch was already on top of develop, so there was nothing to do.

    In order to actually change develop, you would either do a merge, which would end up as this:

    git checkout develop
    git merge --no-ff feature
    
                                 develop
                                    v
    1---2---3---4---5---6-----------M
                         \         /
                          7---8---9
                                  ^
                               feature
    

    or a fast-forward merge which would end up as this:

    git checkout develop
    git merge --ff-only feature
    
                                 develop
                                    v
    1---2---3---4---5---6---7---8---9
                                    ^
                                 feature