Import a golang module with LFS objects

Viewed 583

I need to import a module with LFS objects into my go project. I already added the module to go.mod, but when the go tools download the dependencies into my ~/go/pkg/... folder, the LFS objects are not downloaded. Instead of the full object, I get the LFS metadata. This causes my build to fail.

I already went through the go get and go mod docs but couldn't find anything on this topic. The only workaround I've found to far is to manually download the files post go mod download, but I'm looking for a more official solution.

1 Answers

Assuming go get uses the standard Git commands to download and fetch repositories, it should be sufficient to have installed Git LFS and run git lfs install. That will install the Git filter configuration that Git LFS needs in your per-user Git configuration and then cloning or pulling the changes should result in the proper LFS files being checked out.

You may also want to use the --skip-repo option if you run the command outside of a repository.

Related