Merge conflicts in go.sum

Configure git to automatically handle merge conflicts in go.sum

Merge conflicts in go.sum
Photo by Richard Lee / Unsplash

When rebasing a branch in a Go project, you may encounter git conflicts on your dependencies. While the go.mod file should still be handled manually, it seems safe to automatically merge the go.sum file by keeping both versions, and running a go mod tidy afterwards.

Git can handle the first part by itself:

# if you don't already have a global attributes file:
git config --global core.attributesfile $HOME/.gitattributes

# then tell git to keep both versions when merging go.sum
echo "go.sum merge=union" >> $(git config --global core.attributesfile)

As always when dealing with dependencies and go.mod, remember to cleanup with go mod tidy.