DEV Community

Clavin June
Clavin June

Posted on • Originally published at clavinjune.dev on

2 2 1 1 1

Go Get Golang Private Module

Sunday Snippet #2 go get golang private module

I assume before fetching golang private module, you already have put your public SSH key on your git repository.

$ mkdir example && cd example
$ go mod init example
go: creating new go.mod: module example
# this is my private repo, this attempt will produce error
$ go get github.com/clavinjune/testing@latest
go get github.com/clavinjune/testing@latest: module github.com/clavinjune/testing: git ls-remote -q origin in [redacted]: exit status 128:
    fatal: could not read Username for 'https://github.com': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.

# change the https to ssh, go get will try fetching your private module using your SSH key
$ git config --global --add url."git@github.com:".insteadOf "https://github.com/"
$ go get github.com/clavinjune/testing@latest
go get: added github.com/clavinjune/testing v1.0.0
# success! But if above method still doesn't work set GOPRIVATE first
$ go env -w GOPRIVATE="github.com/clavinjune/*"
# then, go get again
Enter fullscreen mode Exit fullscreen mode

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs