Field Note

Reducing Large Git Merges with `git checkout`

git git-merge-conflict-resolution git-checkout
Git logo
Posted on Friday, July the 4th 2025
1 min read
Large Git merges can become complicated especially if there are a lots of unrelated changes to deal with. There is a little trick using `git checkout`, however, that may be useful to resolve merge conflicts quickly.

Let’s, for instance, say we are merging changes from main into the current branch

git merge main

Now, assuming we didn’t change any Golang test files—i.e. those ending with _test.go—and simply want to resolve the conflicting changes by taking over the changes on main, then we may run

git checkout --theirs **/*_test.go

(And vice versa using git checkout --ours **/*_test.go if we want to resolve conflicts by keeping the changes in the current working tree.)

If we also want to delete files that were deleted in the current working tree or main, we may additionally pass the --no-overlay option.

For example,

git checkout --theirs --no-overlay **/*_test.go 

resolves conflicts on Go test files in favor of the changes on main and, moreover, deletes matching files from the current working tree, if they were deleted on the main branch.

friedrichkurz.me

© 2025 Friedrich Kurz

Privacy Policy