How to build Go packages from private repositories

Let’s say you have a Go package on a private repository which is tagged as v0.0.1,

and want to build an application with it:

# (your) go package on a private repository

1. Create a go.mod file with the private repository

This will be the go.mod file of your application:


go 1.13

require ( v0.0.1

2. Edit .gitconfig file

Put following lines to your ~/.gitconfig file:

[url "ssh://"]
  insteadOf =


Then set an environment variable, GOPRIVATE:


You can put above lines in the .rc files, or even in your build scripts.

Then you’ll be able to build your application with packages on private repositories :-)

Please let me know if there is a better way!