Loading...

Switching remote git repositories from HTTPS to SSH

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

If you access the git repository via HTTPS you have to provide each time authentication data. Switching to SSH is more convenient and secure. After adding your public SSH key to the repository in GitHub (or any other) you can access the repository with SSH. To switch your local git repository:

# show current remote urls
git remote -v
# switch remote
git remote set-url origin git@github.com/user/repository.git
# check again
git remote -v

Replace user and repository and you are done. You may consider that other providers like Atlassian Stash or Bitbucket have another syntax.

# Bitbucket example with user
git remote set-url origin ssh://git@bitbucket.org:user/repository.git
# Atlassian Stash example with default ssh port
git remote set-url origin ssh://git@stashhost:7999/repository.git
Please remember the terms for blog comments.