How to do 'git checkout --theirs' for multiple files (or all unmerged files)

isherwood picture isherwood · Jul 23, 2014 · Viewed 32.6k times · Source

Say I have this after attempting a merge and upon entering git status:

# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#   added by them: myfile1.xhtml
#   added by them: myfile2.xhtml
#   added by them: myfile3.xhtml

... and I know I want to do this for each of those files:

git checkout --theirs myfile1.xhtml
git add myfile1.xhtml

... but there are many of them. How might I do them as a batch?

Answer

isherwood picture isherwood · Dec 23, 2014

The solution for my case ended up being to simply use a wildcard in the directory path, since the files were grouped:

git checkout --theirs directory_name/*
git add directory_name/*

This may also work, according to helios456:

git checkout --theirs directory_name/.