When I merge a branch in Git to master I often get merge conflicts. Is there a way to merge a branch and just overwrite the stuff in the current branch?
Asked
Active
Viewed 4.8k times
56
-
You mean like in SVN - use theirs? – stdcall Jan 11 '13 at 10:14
-
My experience with automatically choosing one side for a merge has never been good .. also, isn't it the point of merge conflicts to check what other people changed near the same lines as you before removing their changes? – KristofMols Jan 11 '13 at 13:15
-
4It's me that made the branch locally in the first place.. it's just quicker than trawling through the file and removing the conflicts – John Hunt Jan 11 '13 at 16:42
2 Answers
76
Add -X ours argument to your git merge command.
Say you are working in your local branch. Then you want to merge in what went in the master:
git merge -X ours master
On the other hand if you are in master and want to merge your local branch into master then @elhadi rightly says you should use theirs:
git merge -X theirs somebranch
kmkaplan
- 18,235
- 4
- 50
- 62
-
1@elhadi My understanding is that John Hunt wants to push *his* work, not theirs. – kmkaplan Jan 11 '13 at 10:34
-
1It was a local branch yes. Eg I've been working on somebranch and want to merge/replace somebranch files in place of the ones on master. – John Hunt Jan 11 '13 at 16:43
-
This still give the "files would be overwritten by merge" error instead of overwriting them with `-X theirs`. – feeela Jan 18 '22 at 11:48
7
To overwrite your stuff in your branch and take their work, you should make
git merge -X theirs {remote/branch} --> example:origin/master
PhD
- 10,822
- 12
- 60
- 109
elhadi dp ıpɐɥןǝ
- 4,397
- 1
- 28
- 31