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?– stdcallJan 11, 2013 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?– KristofMolsJan 11, 2013 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 HuntJan 11, 2013 at 16:42
2 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
-
1@elhadi My understanding is that John Hunt wants to push his work, not theirs.– kmkaplanJan 11, 2013 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. Jan 11, 2013 at 16:43
-
This still give the "files would be overwritten by merge" error instead of overwriting them with
-X theirs
.– feeelaJan 18 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
-
1