gitgithubssh

How to migrate from HTTPS to SSH with GitHub


I cloned my company project repository 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

  • Steps

    1. Create an SSH key: ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

      Enter a 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 space: Adding a new SSH key to your GitHub account

    2. remove the GitHub credentials (if you 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)

    3. Change the remote URL to SSH

      git remote set-url origin <SSH URL>
      

      Example:

      git remote set-url origin git@github.com:username/repo_name.git
      
    4. Enter the passcode of your key

    5. Verify your remote URL has been changed

      git remote -v