Home > Software engineering >  Git rebase returns but nothing happens
Git rebase returns but nothing happens

Time:02-10

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.

CodePudding user response:

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

CodePudding user response:

Well assuming that develop might have changes on the remote which you don't yet have in your local develop branch, your observations of a no-op rebase might be expected. In this case, you could first fetch from the remote, and then rebase on the tracking branch, e.g.

# from your feature branch
git fetch origin
git rebase origin/develop

If you really want to do git rebase develop and have it work, then you would have to separately bring develop up to date with the remote via a pull.

Note that if the above doesn't resolve it, then maybe you don't have any changes in develop, contrary to what you expected.

  • Related