Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly rebase in SourceTree?

SourceTree 1.6.4.0 on Windows 7.

Let's say the following is my starting point:

enter image description here

 C <- master / - A - B <- topic 

I want to rebase topic onto master.
My goal is to have:

  C - A - B   ^       ^ master  topic 

but I end up with:

enter image description here

I can then do

git push origin topic -f 

and I get the intended result, but what is the proper way to do this in SourceTree?

like image 634
Patrick Avatar asked Sep 09 '14 14:09

Patrick


People also ask

What is the golden rule of rebasing?

The Golden Rule of Rebasing reads: “Never rebase while you're on a public branch.” This way, no one else will be pushing other changes, and no commits that aren't in your local repo will exist on the remote branch.

Which is the correct command for rebase?

Checkout to the desired branch you want to rebase. Now perform the rebase command as follows: Syntax: $git rebase <branch name>

Should I commit before rebasing?

The purpose of rebase is make your commits look as if they were changes to the branch you rebase onto. So the most logical way is to incorporate merge conflicts into these commits. No additional commits is required thus.


2 Answers

Update: SourceTree 1.9.1

You can enable force push in Tools/Options/Git/Enable Force Push. After it is enabled you can check "Force Push" check box in the "Push" dialog.

Original answer

You have to do a force push, because topic branch is already published and you are rewriting history. Commits A and B from origin/topic are removed if you rebase.

You should make a merge if you don't want to do a force push, specially if you have a team members already working on topic.

You can't do a force push with SourceTree for Windows yet (see answers at atlassian forums). You can vote for this feature here: https://jira.atlassian.com/browse/SRCTREEWIN-338

like image 100
filhit Avatar answered Oct 05 '22 08:10

filhit


UPDATE: SourceTree Version 2.6.3 (134) (for Mac)

Go to SourceTree/Preferences/Advanced and click the 'Allow force push' checkbox at the top of the 'Advanced' dialog.

This allows for the ability to click Force Push in the push dialog whilst pushing a commit.

Previous versions had this at SourceTree/Preferences/General toward the bottom of the 'General' dialog.

like image 23
jacoballenwood Avatar answered Oct 05 '22 09:10

jacoballenwood