73

I'm trying to merge a git branch (test-development) back into master. There are lots of merge conflicts but I want as many as possible to be resolved via --theirs. Is there a way to tell git to merge with --theirs in bulk?

Haralan Dobrev
  • 7,617
  • 2
  • 48
  • 66
SecondGear
  • 1,093
  • 1
  • 12
  • 18

1 Answers1

134

This will do it (does not just resolve the conflicts but takes their version of the files) if you're mid-merge:

git merge test-development
# Automatic merge failed, a bunch of conflicts!
git checkout --theirs ./path
git add ./path
git commit
piojo
  • 6,351
  • 1
  • 26
  • 36
Ash Wilson
  • 22,820
  • 3
  • 34
  • 45
  • Thanks, I've tried a bunch of variations to no avail. `[sekingerg@centos-sekinger master2]$ git status # On branch master nothing to commit (working directory clean) [sekingerg@centos-sekinger master2]$ git branch * master [sekingerg@centos-sekinger master2]$ git checkout --theirs . [sekingerg@centos-sekinger master2]$ git add . [sekingerg@centos-sekinger master2]$ git commit # On branch master nothing to commit (working directory clean) [sekingerg@centos-sekinger master2]$` – SecondGear Mar 20 '14 at 21:19
  • 1
    Well, you need to actually do the merge -- I edited the merge command into my answer. – Ash Wilson Mar 20 '14 at 22:34
  • 4
    Also: this will bring all of the changes from `test-development` that *don't* conflict into `master`, and accept `test-development`'s version over `master`'s for any that conflict. Is that what you want, or do you want everything to look like `test-development` unconditionally, whever it conflicts or not? – Ash Wilson Mar 20 '14 at 22:36
  • This really helped. As it turned out, it was only half my problem. I use VitrualBox on a windows machine and have my git repo on a shared drive which means it's really on a NTFS partition. We've had a number of file renames where only case was changed in the filenames. Doing this over the shared folder proved to be extremely problematic. I cloned the master onto a ext4 partition and all of the odd errors I was seeing are gone. – SecondGear Mar 21 '14 at 15:05
  • 5
    WARNING: this will silently overwrite any changes in your local workspace, even in files that are not conflicted. – Rene Wooller Jan 19 '16 at 04:33
  • 5
    Additional tip: You can do this for multiple files like this: `git checkout --theirs ./*` and `git add ./*` – Spenhouet Jun 09 '20 at 07:27
  • Anyway to update the answer w/ what to do if you're not mid merge? Ie from scratch? Just to make this a great reference... – Adam Hughes Apr 26 '21 at 14:17
  • @Spenhouet legend! – PostCodeism Jun 03 '21 at 19:42
  • @Spenhouet `grep -lr '<<<<<<<' . | xargs git checkout --theirs && git add --all` seems like a better option – alper Jul 24 '21 at 23:12
  • I get an error with multiple files that have been removed, "does not have their version". How can I get around this? – Jeffrey Tillwick Oct 31 '22 at 20:22