Skip to content

Instantly share code, notes, and snippets.

@niraj8
Last active May 24, 2022 12:24
Show Gist options
  • Save niraj8/d5a5c4f925ad772fe46ae05da96ce794 to your computer and use it in GitHub Desktop.
Save niraj8/d5a5c4f925ad772fe46ae05da96ce794 to your computer and use it in GitHub Desktop.
Update .git/config files for local repos to use SSH

If you have SSH keys added to your GitHub account you can switch your repos to use SSH

  1. Disable credential.helper
  • Check if credential.helper is set to anything git config -l --global
  • Unset credential.helper with git config --global --unset credential.helper
  1. Verify URLs are as expected. Then add a -i to sed to update in place(in the .git/config file)
find . -type f -path '*.git*/*' -name 'config' | xargs -I {} sed 's/https:\/\/github.com\//git@github.com:/g' {} | grep url
  1. ❗️ Update .git/config files

Below command will update the .git/config files in place. Please make sure you understand the below command before running it.

find . -type f -path '*.git*/*' -name 'config' | xargs -I {} sed -i '' 's/https:\/\/github.com\//git@github.com:/g' {}
  1. gh cli: gh config set git_protocol ssh --host github.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment