Go Modules, you will have both a go.mod and a go.sum file within your coding repository. A question often asked is whether you should commit the sum portion of the file as it’s automatically generated. These files help manage the dependencies of your project and they differ by the go.mod file being human-friendly, listing the libraries used within the project, and the go.sum listing the very specific vendor versions of each dependency (not just your direct ones, but also the whole tree).

">

Should I Commit the go.sum File to the Repo? (original) (raw)

Written byEdd Turtle on gophercoding.com
on 31st of October 2023

TL;DR Yes, probably.

Using Go Modules, you will have both a go.mod and a go.sum file within your coding repository. A question often asked is whether you should commit the sum portion of the file as it’s automatically generated. These files help manage the dependencies of your project and they differ by the go.mod file being human-friendly, listing the libraries used within the project, and the go.sum listing the very specific vendor versions of each dependency (not just your direct ones, but also the whole tree).

By committing the sum file then you can share with fellow developers (or cloud platforms) the exact same versions that you used to build it. All this helps keep bugs un-intendended side effects to a minimum.

The down-side of doing this though is that you can encounter merge conflicts when the file is changed as git (if you’re using git?) is not always the best on automatically generated files like these - as keys will be different.

Author Edd Turtle

Edd is a PHP and Go developer who enjoys blogging about his experiences, mostly about creating and coding new things he's working on and is a big beliver in open-source and Linux.

Tweet me!☕ Buy me a Coffee