Skip to content

Instantly share code, notes, and snippets.

@dmitshur
Last active September 17, 2023 07:35
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: 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.

$ 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:

@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?

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