$ git remote -v
origin https://github.com/my-repo/site-web.git (fetch)
origin https://github.com/my-repo/site-web.git (push)
我已经设置了ssh并运行了一个shell脚本,如下所示:
ssh -T git@github.com
git reset --hard
...
git pull
但是我仍然被提示输入密码。我认为远程服务器必须是git@github.com才能使ssh正常工作。我有四个目录...
a/
b/
c/
和d/
,它们都指向此远程目录。但是我真的只希望ssh在a/
中工作。我很高兴继续为其他人使用https。我该怎么办?
最佳答案
如果a /是git仓库,则可以简单地更改其远程:
cd a
git remote set-url origin git@github.com/my-repo/site-web.git
但是,如果
a
,b
,c
和d
是同一存储库的文件夹,则将更改所有它们的来源。要仅对
a/
使用ssh,您将需要一个separate clone, as a sparse checkout,以便仅使用a/
内容(并为该单独的克隆提供正确的远程URL)。
关于github - 如何设置git使用ssh而不是https?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27499004/