'How to migrate from HTTPS to SSH github

I cloned my company project repo using HTTPS, I want to migrate into SSH because it conflicts with my personal git account. how can I migrate into SSH instead of using HTTPS?



Solution 1:[1]

Steps

  1. Create an ssh key $ ssh-keygen -t rsa -b 4096 -C "[email protected]"

Enter passcode and then copy it pbcopy < ~/.ssh/id_rsa.pub If you don't have pbcopy, xclip or vim just type: cat ~/.ssh/id_rsa.pub

add it into your GitHub Adding a new SSH key to your GitHub account

  1. remove GitHub credentials (if u were using HTTPS there is a high possibility GitHub credentials are saved in your system), we don't need those credentials since we are using SSH (Optional step)

  2. Change the remote URL to SSH

>git remote set-url origin <SSH url>

example : git remote set-url origin [email protected]:username/repo_name.git

  1. Enter the passKey

  2. Verify your remote url has been changed git remote -v

Solution 2:[2]

You need to generate ssh key, add it to your profile and then change the url

Source: https://help.github.com/en/enterprise/2.15/user/articles/adding-a-new-ssh-key-to-your-github-account

Generating ssh key

  • Open Git Bash.
  • Run ssh-keygen and follow the on-screen messages (or simply click Enter till it over)
  • Copy the key file (the content of the public key) located in:

     ~/.ssh/id_rsa.pub
    

Add key to Github

  • In the upper-right corner of any page, click your profile photo, then click Settings. enter image description here

  • In the user settings sidebar, click SSH and GPG keys.
    enter image description here

  • Click New SSH key or Add SSH key. enter image description here

  • Paste your key into the "Key" field. enter image description here

  • Click Add SSH key.
    enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 CodeWizard