Search code examples
gitrebasegithub-desktop

Rebase button is disabled while trying to rebase child branch with parent


I have a branch named Test-Parent.

I have created Test-Child branch from Test-Parent.

I pulled the Test-Parent branch in my GitHub Desktop and created a file TempFile.txt and pushed.

I need to rebase the Test-Child branch with Test-Parent.

I pulled the Test-Child branch in GitHub Desktop.

Went to Branch-> Rebase Current Branch:

enter image description here

But the Rebase button is disabled and message is coming as This branch is up to date with Test-Child:

enter image description here

When I compare this branch with Test-Parent, Able to see the difference:

enter image description here

Can you please help me how can I rebase Test-Child with Test-Parent from GitHub Desktop?


Solution

  • tl;dr: Your branch has no new commits on it yet. In this case you can simply merge Test-Parent into Test-Child with fast-forward. That should be possible in GH Desktop and has the same effect as the rebase you wished to do. In your last screenshot it is offering this option, but with "Create a merge commit" selected. I'm guessing if you click on the arrow you can select a different option like "Regular Merge" or something like "Fast-Forward Merge".

    What's going on?

    Most GUI tools do a basic rebase. For example, if you have Test-Child checked out, and you wish to rebase your branch onto Test-Parent, it's equivalent to the command:

    git rebase Test-Parent
    

    That will do a hard reset of your branch to Test-Parent, and then for each of the commits on your branch that aren't on Test-Parent, it will cherry-pick them one by one. If you don't have any new commits on your branch, then it only does the reset portion of the command.

    In your scenario, conceptually, there's nothing to actually rebase when your branch is only behind and doesn't have new commits of its own yet, so I don't fault GH Desktop for not offering the option in this case. That being said, I'd probably prefer that it still allow it anyway, just because that's how it works from the command line. Some people may blindly rebase their branch whether it needs it or not, just out of habit, and on a fresh branch with no new commits they would expect it to still update their branch even though nothing gets rewritten.

    Other ways to update your branch

    In your particular case, if you have a branch named Test-Child which was created from Test-Parent, and since then some new commits were added to Test-Parent and you have no new commits yet on Test-Child, there are multiple ways to update your currently checked out Test-Child branch, including:

    1. Merge: git merge Test-Parent --ff-only
    2. Reset: git reset --hard Test-Parent
    3. Recreate: git switch -C Test-Child Test-Parent
    4. Rebase: git rebase Test-Parent
    5. there are others...

    Note that as soon as your branch has new commits on it, then to update your branch you can only use #4, and with new commits the rebase option will become available in GH Desktop too. (Alternatively, you could update your branch with a regular merge without the --ff-only option.)