Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SourceTree - make branch the new master

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 :/

like image 808
Dustin Silk Avatar asked Apr 13 '15 13:04

Dustin Silk


People also ask

How do I create a master branch in Sourcetree?

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.


2 Answers

You can do the following:

  1. From your feature-01 branch: git merge --strategy=ours master
  2. Then from your master branch: 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.

like image 193
Яois Avatar answered Oct 24 '22 02:10

Яois


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:

merge options


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

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)

like image 4
VonC Avatar answered Oct 24 '22 01:10

VonC