Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Created November 24, 2020 00:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save magnetikonline/3ceec9ece11375393ab5781d9370ee99 to your computer and use it in GitHub Desktop.
Access Golang private modules within a GitHub organization.

Golang private modules within a GitHub organization

You've got Golang modules within a private repository or an organization and would like to go get them.

For this example the GitHub organization will be spacely-sprockets.

Howto

Set GOPRIVATE (ideally placed in your .bashrc / dotfiles):

export GOPRIVATE="github.com/spacely-sprockets"

Update .gitconfig:

$ git config --global \
  url."ssh://git@github.com/spacely-sprockets".insteadOf \
  "https://github.com/spacely-sprockets"

Will add a block like the following:

[url "ssh://git@github.com/spacely-sprockets"]
  insteadOf = https://github.com/spacely-sprockets

And finally, lets test:

$ GO111MODULE="on" go get github.com/spacely-sprockets/widgets-golang
go: downloading github.com/spacely-sprockets/widgets-golang...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment