Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a connection to GitHub from SSH to HTTPS?

I created my first repository in GitHub yesterday. When making the connection I used SSH instead of HTTPS, so I went through a little painful SSH key creation and connection process. At some point I got stuck and the connection failed. I wondered at that moment how I could revert the process I started and begin with a HTTPS connection instead. Happily, today I got the connection working through SSH but I'm wondering about the value of being able to change the type of connection (SSH vs HTTPS) and if there is a way to do it.

like image 894
dickbarba Avatar asked Jun 06 '15 13:06

dickbarba


People also ask

How do I change SSH to HTTPS in GitHub?

Switching remote URLs from SSH to HTTPS Change your remote's URL from SSH to HTTPS with the git remote set-url command. Verify that the remote URL has changed. The next time you git fetch , git pull , or git push to the remote repository, you'll be asked for your GitHub username and password.

Should I use SSH or HTTPS for GitHub?

While SSH is usually considered more secure, for basic usage of Github, HTTPS authentication with a password is acceptable enough. In fact, Github themselves defaults to and recommends most people use HTTPS.


2 Answers

Assuming your remote is called origin, run

  • git remote set-url origin https://...
  • git remote set-url --push origin https://...

You can view the configured remotes with git remote -v, which should now show your updated URLs.

See the documentation for git-remote for more details.

like image 93
Chris Avatar answered Oct 24 '22 07:10

Chris


here are some aliases (oneliners) to switch your repo from ssh to https and back. Assuming your default remote is named origin and your remote is github.com

alias git-https="git remote set-url origin https://github.com/$(git remote get-url origin | sed 's/https:\/\/github.com\///' | sed 's/[email protected]://')"
alias git-ssh="  git remote set-url origin [email protected]:$(    git remote get-url origin | sed 's/https:\/\/github.com\///' | sed 's/[email protected]://')"

they're a bit longer than necessary to make them idempotent

like image 20
Harry Moreno Avatar answered Oct 24 '22 08:10

Harry Moreno