Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git How to merge a branch into the master branch by completely overwriting master branch

Tags:

git

git-branch

I started work on the master branch. Almost one year ago, I created another branch dev in which I made some changes. From that time on I continued work on dev branch. Now I want to merge dev into master which results in lot of conflicts. I want to merge dev into master by overwriting master branch's contents i.e. for any conflict that arises I want to keep dev branch's version of the code. How can it be done ?

like image 466
Haris ur Rehman Avatar asked Jul 23 '14 21:07

Haris ur Rehman


2 Answers

You can specify the strategy option with -X switch:

git checkout master
git merge -X theirs dev

A bit explanation. The -X theirs means: Use recursive strategy with the merge but fallback to their changes if the strategy cannot resolve the conflict.

This is different from -s ours (for some reason there's no -s theirs) which would be a greedy take ours always solution to conflicts.

git-merge(1) Merge Strategies section provides a deeper explanation on this.

like image 97
Paulo Bu Avatar answered Sep 28 '22 05:09

Paulo Bu


You'll want to use a "merge using theirs" strategy, which is set using the -X flag

git checkout master
git merge -X theirs dev
like image 38
KevinL Avatar answered Sep 28 '22 04:09

KevinL