Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I commit vendor directory with go mod?

Tags:

go

go-modules

I am using go modules on go1.12 to handle my Go dependencies. Is it best practice to also commit the vendor/ directory into version control?

This is somewhat related to Is it best-practice to commit the `vendor` directory? which asks this question in the case of using dep. With dep, commiting vendor/ is the only way to get truly reproducible builds. What about for go modules?

like image 505
hongsy Avatar asked Mar 26 '20 10:03

hongsy


1 Answers

Unless you need to modify the vendored packages, you shouldn't. Go modules already gives you reproducible builds as the go.mod file records the exact versions and commit hashes of your dependencies, which the go tool will respect and follow.

The vendor directory can be recreated by running the go mod vendor command, and it's even ignored by default by go build unless you ask it to use it with the -mod=vendor flag.

Read more details:

Go wiki: How do I use vendoring with modules? Is vendoring going away?

Command go: Modules and vendoring

Command go: Make vendored copies of dependencies

like image 152
icza Avatar answered Sep 21 '22 19:09

icza