3

I have two branches. One is master, and the other one i myBranch and they look something like this:

master | | myBranch | / | / |/ | 

I want to merge them into one branch, keeping all the changes from the master branch, not keeping anything from myBranch.

5
  • I think I know what you mean, - and that I have had the same problem, but the way you've written your question, it sounds as if the answer is "keep master and throw away myBranch" .... Commented Dec 20, 2012 at 8:41
  • That sounds like just keeping the master branch and deleting myBranch. Commented Dec 20, 2012 at 8:41
  • If you don't want the changes in myBranch why doing a merge? Commented Dec 20, 2012 at 8:44
  • Yes I want to keep master but I don't want to delete myBranch because I'm using the same branch for another project (this was stupid idea, right?) Commented Dec 20, 2012 at 8:47
  • 1
    Sounds like your wanting to create a new repo for myBranch first and then delete myBranch from this repo? Commented Dec 20, 2012 at 8:51

3 Answers 3

10

Merge the branch using the ours merge strategy:

git checkout -b new-branch master git merge -s ours myBranch 

Note that this is quite different from the -X ours, as initially stated in Koraktor's answer. -X ours is an option to the recursive strategy, which would still keep all changes from myBranch, but prefer resolutions from master in case of conflict. -s ours, on the other hand, completely ignores changes introduced by myBranch.

Sign up to request clarification or add additional context in comments.

Comments

3

Just delete the branch: git branch -d "myBranch"

Comments

2
$ git checkout -b new-branch $ git merge -s ours myBranch 

If you want this to happen directly on master, just omit the first command.

PS: "user4815162342" is right, I meant -s not -X.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.