Im using GIT and Sourcetree as the gui.
I've got two branches - master and feature-01. I now want to overwrite everything on master with whats on feature-01.
I had to do this after having to roll back a few changes on master. however i rolled back the changes on the new branch, got the branch to be 100% where i want master to be but now when i merge the two - master is keeping all the rolled back changes that it should have discarded like in the branch :/
Create a branch and make a changeFrom Sourcetree, click the Branch button. From the New Branch or Create a new branch field, enter wish-list for the name of your branch. Click Create Branch or OK.
You can do the following:
feature-01 branch: git merge --strategy=ours master
git merge feature-01
The first command will create a new (merge) commit from the two branches, but ignoring all what's in master by using the --strategy=ours option. Then, the second command will "advance" master to this new commit.
At this point you will have your feature contents in master. With this option you won't need to "reset" the remote or anything similar; it will just put into master all the work you did in feature.
Is this possible in SourceTree?
No, it is not directly possible, because a merge --ours is not supported in Sourcetree.
(I have tested it with the latest 2.1.11.0, with Git 2.14.1 embedded, Sept. 2017).
See SRCTREEWIN-1237 (... from 2013!)
I need to use the ours strategy i.e. merge myBranch into master, discarding any changes on myBranch
git merge -s ours myBranch
This is still not available when merging two branches:

As mentioned in this article, you would need to define a custom action:

That will allow you to emulate the merge --ours step of the following sequence
git checkout feature-01
git merge --strategy=ours master
git checkout master
git merge feature-01
The checkout and simple merge are supported in SourceTree. The custom action allows you to make the merge --ours step.
And then, master content will be replaced by feature-01 content.
Entirely from SourceTree alone.
For mercurial, following "Replace the content of a hg branch", you would need to create a custom action (as illustrated above), for the command hg branch -f (the -f option is not available in the normal branch dialog)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With