Skip to content

Instantly share code, notes, and snippets.

@fahadsiddiqui
Created September 2, 2024 10:19
Show Gist options
  • Save fahadsiddiqui/ec7b71183d197560e0d34e41f2e0a22f to your computer and use it in GitHub Desktop.
Save fahadsiddiqui/ec7b71183d197560e0d34e41f2e0a22f to your computer and use it in GitHub Desktop.
Go private package configuration with custom SSH keys.

Go private packages with different SSH config

Update your GOPRIVATE env

export GOPRIVATE=github.com/yourorg/yourrepo1,github.com/yourorg/yourrepo2

Check your SSH key HostName from .ssh/config and use it in ~/.gitconfig

Let's say, you had the hostname r1.github.com for the yourrepo1 (when creating a deploy key for yourrepo1) and r2.github.com for the yourrepo2 (when creating a deploy key for yourrepo2)

[url "ssh://git@r1.github.com/yourorg/yourrepo1"]
	insteadOf = https://github.com/yourorg/yourrepo1
[url "ssh://git@r2.github.com/yourorg/yourrepo2"]
	insteadOf = https://github.com/yourorg/yourrepo2

This should be inside your ~/.gitconfig.

Alternatively, use --global with git config

git config --global url."ssh://git@r1.github.com/yourorg/yourrepo1".insteadOf "https://github.com/yourorg/yourrepo1"
git config --global url."ssh://git@r2.github.com/yourorg/yourrepo2".insteadOf "https://github.com/yourorg/yourrepo2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment