119

I think I am confused on how to use SourceTree GUI to do git rebase. I have two branches "master" and "dev". As seen, the two branch diverged. I want to do a rebase on "dev" branch, using command line, this would be:

git checkout dev
git rebase master

enter image description here

I would have expected to right click "dev", and choose "Rebase current changes onto dev". I assume current changes means "new commits on master". But picking this option seems have no effect whatsoever. What would be the correct steps?

python152
  • 1,811
  • 2
  • 15
  • 18

2 Answers2

170

But picking this option seems have no effect whatsoever.

Yes, because current changes are the one of the current branches, which is dev.

Rebasing dev on top of dev means an no-op.

git checkout dev
git rebase master

That means: current branch is dev: to be rebased on top of master.

So in SourceTree, you need to right-click on master (while dev is checked out), and select:

Rebase current changes onto master

Howe adds in the comments:

Current Naming of "rebase current changes onto [branch]" is misleading. Check out this improvement discussion SRCTREE-1578.

After finding myself baffled attempting to bring a feature branch up to date with development and failing, I've come to realize that the left-pane context menu item labeled “rebase current changes onto $somebranch” actually does the opposite of what its name suggests:
it rebases the current branch to the state of $somebranch;
In other words it rebases $somebranch onto (or into) the current branch, not the other way around. (Right?)

The preposition “onto” in the current text is misleading; it implies that the object of the sentence ($somebranch in my example) will receive the changes.
In fact, it is the opposite that will occur.
The absence of the current branch's name adds to the confusion.

A re-wording that improves the sentence structure and includes the name of the affected branch would afford a huge win for clarity.
For example:

rebase $currentbranch to head of $somebranch
rebase $somebranch onto $currentbranch
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 17
    For context, the downvote is from [deadman](http://stackoverflow.com/users/2586651/deadman) who posted [an answer earlier](http://stackoverflow.com/a/39929671/6309) without addressing SourceTree at all. I downvoted and explained my criticisms in a comment. Apparently, deadman did not appreciate the constructive remarks I made. – VonC Oct 08 '16 at 11:45
  • 1
    Will that change the master branch? I would just like to update my dev branch with the latest changes of the master branch - and later merge my dev branch into master. Will the described way do this task? – ESP32 Jun 21 '17 at 12:27
  • 1
    @Gerfried No, it won't change master: the all idea of a rebase is to replay your commits on top of a branch (which does not realized it is use by that rebase). But in your case (I would just like to update my dev branch with the latest changes of the master branch), a merge is preferable, especially if you have already pushed dev. – VonC Jun 21 '17 at 13:43
  • thank you, I will try to rebase first - because when I merge into both directions the tree will become quite complex. – ESP32 Jun 21 '17 at 14:07
  • 2
    @Gerfried Agreed. As long as dev was not pushed, you can rebase on top of master. – VonC Jun 21 '17 at 14:08
  • Should I make sure current change on dev is committed but not pushed? – Felix Nov 14 '17 at 14:10
  • @Felix Yes, or make sure you are the only one working on dev (in which case, a force push won't matter) – VonC Nov 14 '17 at 14:20
  • 37
    Sourcetree should change the wording to "Rebase latest changes from Master into Dev" for better clarification. – Timo Ernst Mar 22 '18 at 14:08
  • 4
    Current Naming of "rebase current changes onto [branch]" is misleading. Check out this improvement discussion: https://jira.atlassian.com/browse/SRCTREE-1578. – Zihao Zhao Oct 08 '18 at 21:37
  • @Howe Thank you. I have included your comment in the answer for more visibility. – VonC Oct 09 '18 at 07:18
  • 4
    seriously atlassian couldnt find a way to make it even more confusing : / – Sainath S.R Jun 24 '19 at 15:16
  • 2
    Thank you for the explanation. The wording in Sourcetree baffled me completely – Chrisii Jul 22 '19 at 17:32
  • 1
    Several years have passed and it still remains confusing as hell. Simply tell that current branch base will be updated to selected branch HEAD. Current wording can easily be understood as placing your changes on the other branch. – htafoya Mar 03 '21 at 07:37
  • 1
    Just adding to the hilarity of this multi-year impasse situation. The current wording is atrocious and plain wrong since *onto* means, semantically, the opposite of what really happens. A simple change to "on" would have sufficed, but we're almost 6 years in, so nothing will change, and people will still need to check out StachExchange and waste hours of their time to understand something others have developed poorly. – F. Remonato Nov 18 '21 at 11:11
  • 1
    @F.Remonato I agree. I just translate "onto" in my head by "on top of", and that is enough for me to clear out any confusion. – VonC Nov 18 '21 at 13:42
  • Not sure if by accident or in some attempt to clarify but the confirmation dialog uses "on to" instead of "onto". "Are you sure you want to rebase your current changes on to ". – Gabe Mar 31 '22 at 11:48
  • @Gabe Strange indeed. I do not see any " on to " in https://git-scm.com/docs/git-rebase – VonC Mar 31 '22 at 14:27
  • WHY on earth is this upvoted and accepted as an answer? This is not the answer – tpbafk Aug 31 '23 at 08:22
3

Please follow step by step:

Quick note: I assume your main branch is main but some people has master. I will call your-default-branch. Current branch is your-current-branch.

  1. Sourcetree > Settings... > Advanced > Check "Allow force push" box because we will need it.
  2. Checkout your-current-branch.
  3. Now, just come on your-default-branch with your mouse and just right click.
  4. Click "Rebase current changes onto your-default-branch"
  5. Now, do not scare. Yes you have Pull and Push numbers. This is good because you can see differences of your local and remote branches. Keep going!
  6. Look at your-current-branch commits. They should make sense.
  7. Right-Click on your-current-branch.
  8. Select "Push to origin/your-current-branch".
  9. Unselect all branches except your local and remote branches.
  10. Check "Force push" box.
  11. Click OK and done!

Note: When you merge your-default-branch into your-current-branch, after click merge button, just select "Merge Fetched" option and only select "Rebase instead of merge(...)" option.

canerkaseler
  • 6,204
  • 45
  • 38
  • appreciate the steps. they were very helpful. but only one thing, please add a step(s) to take when there is a merge conflict. – sbolla Aug 15 '23 at 21:04