简体   繁体   English

在使用https克隆后,如何SSH git存储库?

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

I have a repository that I have already cloned on my computer using https . 我有一个已经使用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. 我想将此存储库设置为ssh这样我每次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? 关于如何将这个https克隆的存储库转换为ssh而不需要真正重新克隆它的任何建议,这样我就可以避免一直输入我的凭据?

There is a pretty good documentation from GitHub: GitHub上有一个很好的文档:
https://help.github.com/en/articles/changing-a-remotes-url#switching-remote-urls-from-https-to-ssh 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 user@example.com:PATH/REPOSITORY

You should remove your HTTP remote (for example with origin ): 您应该删除HTTP遥控器(例如,使用origin ):

git remote remove origin

and add the SSH remote instead 并添加SSH远程

git remote add origin user@example.com: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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM