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?
-
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
3 Answers
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

- 18,655
- 4
- 51
- 65
-
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
-
To overwrite your stuff in your branch and take their work, you should make
git merge -X theirs {remote/branch} --> example:origin/master

- 11,202
- 14
- 64
- 112

- 4,763
- 2
- 30
- 34
-
1
-
-
I think, your remote doesn't exist, see this topic: https://stackoverflow.com/questions/16862933/how-to-resolve-gits-not-something-we-can-merge-error – elhadi dp ıpɐɥןǝ Nov 14 '22 at 14:59
I have found merge doesn't really make the target branch a mirror copy of the source branch.
If that is what you are after, in order to get the branches 100% in sync I have used this procedure:
git merge -X theirs somebranch
git reset somebranch --hard
This will reset the state of the current branch to the HEAD of somebranch
post merge. In some cases, you might also want to cleanup your working directory if it is dirty with uncommitted files, the whole procedure would then look like this:
git merge -X theirs somebranch
git reset somebranch --hard
git clean -f

- 5,175
- 2
- 40
- 36