如何通过SSH协议克隆Github Gist?

don*_*llo 59 git gist github

Github似乎真的希望我们使用HTTPS协议来使用Gists,例如,他们只在Gist页面上列出HTTPS网址 - 例如https://gist.github.com/donatello/5834862

是否可以使用SSH协议克隆Gist?

don*_*llo 89

对的,这是可能的:

git clone git@github.com:5834862.git
Run Code Online (Sandbox Code Playgroud)

当然,只需用您自己的Gist ID替换即可.

  • 您很可能还希望在命令行上传递要点名称: git clone git@github.com:5834862.git gist_name (3认同)
  • 您编辑了问题以适合您的答案?:D经典!现在,答案42是什么问题?;) (2认同)

xer*_*ero 15

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 git@gist.github.com:5834862.git


Ben*_*kin 13

gist页面的下拉列表现在具有Embed/Share/Clone HTTPS/Clone SSH选项:
要点下拉列表
显示非显而易见的技巧是省略用户名:

  • 克隆HTTPS:
    https://gist.github.com/b6f4a53fac485f75afb9150d03efb2f6.git
    无论是否使用.git,或者使用或不使用用户名都可以使用:( https://gist.github.com/cben/b6f4a53fac485f75afb9150d03efb2f6 通常在github上,规范浏览URL也适用于git)

  • 克隆SSH:
    git@gist.github.com:b6f4a53fac485f75afb9150d03efb2f6.git
    AKA 无论有没有为我工作,但不能使用用户名.
    ssh://git@gist.github.com/b6f4a53fac485f75afb9150d03efb2f6.git
    .git


我启用了github 2FA,这使得HTTPS很痛苦所以我总是想要SSH; 以下~/.gitconfig是推送所有要点的翻译:

[url "ssh://git@gist.github.com/"]
    # 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/
Run Code Online (Sandbox Code Playgroud)

对于常规(非要点)回购:

[url "ssh://git@github.com/"]
    pushInsteadOf = https://github.com/
[url "ssh://git@bitbucket.org/"]
    pushInsteadOf = https://bitbucket.org/
[url "ssh://git@gitlab.com/"]
    pushInsteadOf = https://gitlab.com/
Run Code Online (Sandbox Code Playgroud)