Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Access private repositiories in Go projects hosted on a remote server (using SSH)

Setup private Go modules

You have a git repositiory on a remote server. This is probably a VPS you have online at Digital Ocean, AWS, or some other hosting company. Could also be a docker container or raspberrypi under your desk.

Regardless, you can include the repositiory in your go projects by helping git (which Go uses) to know how to access the code over SSH.

Edit your ~/.gitconfig and make sure your host is listed. Below are examples for github, bitbucket, and my own custom VPS.

[url ""]
        insteadOf =
[url ""]
        insteadOf =
[url ""]
        insteadOf =

Then you can checkout the repo as a go module. Note, you have to use the .git extension.

go get -v -x

Next you need to setup Module configuration for non-public modules (disable proxy sum checking)

go env -w

Now you can use the module in your import paths:

import ""

Related issues and discussions:

Relative Paths

If you are writing multiple sibling modules at the same time it could be beneficial to use relative paths in your modules so you don't have to commit changes and update the dependent module for each change.

In this case, you can use the replace directive.

replace also can be used to inform the go tooling of the relative or absolute on-disk location of modules in a multi-module project, such as:

replace => ../foo

Instead of editing your go.mod file directly use the go mod command:

 go mod edit -replace

You can read more here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.