Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to migrate from HTTPS to SSH github

Tags:

git

github

ssh

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?

like image 707
Eldhopj Avatar asked Dec 07 '22 11:12

Eldhopj


2 Answers

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

like image 195
Eldhopj Avatar answered Dec 11 '22 11:12

Eldhopj


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

like image 44
CodeWizard Avatar answered Dec 11 '22 09:12

CodeWizard