Skip to content

Instantly share code, notes, and snippets.

@ezirmusitua
Last active September 10, 2019 21:39
Show Gist options
  • Save ezirmusitua/f09d22a44c89107264945cb7cc0117dc to your computer and use it in GitHub Desktop.
Save ezirmusitua/f09d22a44c89107264945cb7cc0117dc to your computer and use it in GitHub Desktop.
[SSH Config: Different Repo With Different Key] Use Different Key For Different In Git Repo #ssh #git

配置 SSH Config 对不同 Github Repo 使用不同的 Private Key

  1. Edit SSH Config
# edit config file
vim ~/.ssh/config
# Add Following
Host repo1
  HostName github.com
  User git
  IdentityFile ~/.ssh/key_for_repo1

Host repo2
  HostName github.com
  User git
  IdentityFile ~/.ssh/key_for_repo2
# save
:wq
  1. Update git remote url
cd <path/to/repo1>
# view current remote url
git remote -v

# update remote url
git remote set-url origin repo1:<user>/<repo>.git

# verify remote url
git remote -v

cd <path/to/repo2>
# view current remote url
git remote -v

# update remote url
git remote set-url origin repo2:<user>/<repo>.git

# verify remote url
git remote -v
  1. Use pull command
git pull --rebase
  1. Use clone command
git clone repo1:<user>/<repo>.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment