Skip to content

Instantly share code, notes, and snippets.

@dmitshur
Last active July 14, 2024 16:13
Show Gist options
  • Save dmitshur/6927554 to your computer and use it in GitHub Desktop.
Save dmitshur/6927554 to your computer and use it in GitHub Desktop.
[Legacy GOPATH mode] How to `go get` private repos using SSH key auth instead of password auth.

WARNING: If you're reading this in 2021 or later, you're likely better served by reading:

(This gist was created in 2013 and targeted the legacy GOPATH mode.)

$ ssh -A vm
$ git config --global url."git@github.com:".insteadOf "https://github.com/"
$ cat ~/.gitconfig
[url "git@github.com:"]
	insteadOf = https://github.com/
$ go get github.com/private/repo && echo Success!
Success!

Sources:

@dmitshur
Copy link
Author

This is a very old gist and may not be applicable by now. I added a warning to the top:

WARNING: This gist was created in 2013 and targets the legacy GOPATH mode. If you're reading this in 2021 or later, you're likely better served by reading https://tip.golang.org/cmd/go/#hdr-Configuration_for_downloading_non_public_code and https://golang.org/ref/mod#private-modules.

@moihn
Copy link

moihn commented May 11, 2021

For those who will meet with the same problem: git config --global url."git@github.com:".insteadOf "https://github.com/" works but the local version (git config --local url."git@github.com:".insteadOf "https://github.com/") - doesn't. Likely a git bug.

I encountered the same issue, even if I tried to setup environment variable GIT_CONFIG to point to my local git config file, it is ignored... Do you have a solution that avoids using global ~/.gitconfig file now?

@StevenACoffman
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment