Git merge: accept theirs for multiple conflicts

52,475

This will do it 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
Share:
52,475
SecondGear
Author by

SecondGear

Updated on July 05, 2022

Comments

  • SecondGear
    SecondGear almost 2 years

    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?

  • SecondGear
    SecondGear about 10 years
    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]$
  • Ralf Marmorglatt
    Ralf Marmorglatt about 10 years
    Well, you need to actually do the merge -- I edited the merge command into my answer.
  • Ralf Marmorglatt
    Ralf Marmorglatt about 10 years
    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?
  • SecondGear
    SecondGear about 10 years
    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.
  • Rene Wooller
    Rene Wooller over 8 years
    WARNING: this will silently overwrite any changes in your local workspace, even in files that are not conflicted.
  • Spenhouet
    Spenhouet almost 4 years
    Additional tip: You can do this for multiple files like this: git checkout --theirs ./* and git add ./*
  • Adam Hughes
    Adam Hughes about 3 years
    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...
  • PostCodeism
    PostCodeism almost 3 years
    @Spenhouet legend!
  • alper
    alper almost 3 years
    @Spenhouet grep -lr '<<<<<<<' . | xargs git checkout --theirs && git add --all seems like a better option