35

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?

2 Answers 2

45

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
Sign up to request clarification or add additional context in comments.

1 Comment

For example with a GitHub repo johndoe/helloworld use git remote set-url origin [email protected]:johndoe/helloworld.git. The postfix .git seems to be optional.
7

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.