Github似乎真的希望我们使用HTTPS协议来使用Gists,例如,他们只在Gist页面上列出HTTPS网址 - 例如https://gist.github.com/donatello/5834862
是否可以使用SSH协议克隆Gist?
https://help.github.com/articles/which-remote-url-should-i-use#ssh-readwrite---gitgithubspanspancom
git @ .....是ssh协议
当您复制gist的克隆URL时,它会显示https克隆URL
https://gist.github.com/5834862.git
将https://
改为git@
和/****.git
改为:****.git
所以在这种情况下
git clone [email protected]:5834862.git
gist页面的下拉列表现在具有Embed / Share / Clone HTTPS / Clone SSH选项: 显示非显而易见的技巧是省略用户名:
https://gist.github.com/b6f4a53fac485f75afb9150d03efb2f6.git
无论有没有.git
,有或没有用户名:https://gist.github.com/cben/b6f4a53fac485f75afb9150d03efb2f6
(通常在github上,规范浏览网址也适用于git)[email protected]:b6f4a53fac485f75afb9150d03efb2f6.git
AKA
ssh://[email protected]/b6f4a53fac485f75afb9150d03efb2f6.git
无论有没有.git
,我都可以使用,但不能使用用户名。我启用了github 2FA,这使得HTTPS很痛苦所以我总是想要SSH;以下~/.gitconfig
对推送的所有要点进行翻译:
[url "ssh://[email protected]/"]
# In case I just copy-pasted with username:
# [only works for my (cben) gists, but those are the ones I can push]
pushInsteadOf = https://gist.github.com/cben/
# For gists cloned with official no-username URL:
pushInsteadOf = https://gist.github.com/
对于常规(非要点)回购:
[url "ssh://[email protected]/"]
pushInsteadOf = https://github.com/
[url "ssh://[email protected]/"]
pushInsteadOf = https://bitbucket.org/
[url "ssh://[email protected]/"]
pushInsteadOf = https://gitlab.com/
附:调试insteadOf
和pushInsteadOf
配置的简便方法是运行git remote -v
,它显示了fetch / push将使用的有效URL。
将https://
改为ssh://git@
应该做的伎俩,即改变
https://gist.github.com/donatello/5834862
至
ssh://[email protected]/donatello/5834862
所以git clone ssh://[email protected]/...
应该克隆项目(如果你已经在Github上添加了SSH密钥)
在我个人看来,official document不清楚SSH。
为了使它工作,必须从路径中删除用户名,只留下哈希/数字。
有可能,试试这个:
git clone git@YOURSSHHOST:YOURGISTIDHERE.git