Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to SSH a git repository after already cloned with https?

Tags:

git

I have a repository that I have already cloned on my computer using https. I want to set up this repository as ssh so that I don't have to enter in my username and password every time I git push.

Any suggestions on how I can convert this https cloned repository to ssh without having to actually re-clone it, so that I may avoid entering my credentials all the time?

like image 793
Chris Wong Avatar asked Mar 19 '19 16:03

Chris Wong


Video Answer


2 Answers

There is a pretty good documentation from GitHub:
https://help.github.com/en/articles/changing-a-remotes-url#switching-remote-urls-from-https-to-ssh

In short, this should do it:

git remote set-url origin [email protected]:PATH/REPOSITORY
like image 191
kapsiR Avatar answered Sep 20 '22 16:09

kapsiR


You should remove your HTTP remote (for example with origin):

git remote remove origin

and add the SSH remote instead

git remote add origin [email protected]:path/to/project.git

You will then also have to set the branch's remote again with

git push -u origin master

or

git branch --set-upstream-to=origin master
like image 28
Simon Doppler Avatar answered Sep 19 '22 16:09

Simon Doppler