$ 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:
- https://help.github.com/articles/which-remote-url-should-i-use #You can also use SSH agent forwarding with your deploy script to avoid managing keys on the server.
- http://golang.org/doc/faq #Why does "go get" use HTTPS when cloning a repository?
- https://www.kernel.org/pub/software/scm/git/docs/git-config.html #url.<base>.insteadOf
An alternative to using git@github.com is to generate a personal access token on your GitHub account, grant it repo access, and then use the following instead:
git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"
That should still work with go get -u, and also works with Docker builds (my particular use case, and how I came across your gist).