Skip to main content
Version: 2.23 (prerelease)

Private Modules

Use Golang modules from private repositories


Using Private Modules in Golang

Pants can build go binaries that use modules from private git repositories. To do this specify the private repo(s) in GOPRIVATE and provide credentials for the git repo in your $HOME/.netrc.

Define the GOPRIVATE variable in the subprocess_env_vars section of your pants.toml. The example below shows the .netrc file so that git can authentcate. A simple go.mod shows the inclusion of the private module, nothing special here.

[GLOBAL]
backend_packages.add = [
"pants.backend.experimental.go",
]


[golang]
subprocess_env_vars = [
'GOPRIVATE=github.com/your-user/your-module/*',
'HOME',
]
extra_tools = [
'git',
]
machine github.com
login your-user
password your-token