How to clone Github Gist via SSH protocol?

Github seems to want us to use the HTTPS protocol to use the Gists, for example, they only list the HTTPS url on the Gist page. https://gist.github.com/donatello/5834862

Can I clone a Gist using the SSH protocol?

+43
git github gist
Aug 02 '13 at 14:16
source share
5 answers

Yes, it is possible:

git clone git@github.com:5834862.git 

Just replace your own Gist id, of course.

+76
Aug 02 '13 at 14:16
source share

https://help.github.com/articles/which-remote-url-should-i-use#ssh-readwrite---gitgithubspanspancom

git @ ..... this is the ssh protocol

when you copy clone url for gist it shows you https clone url

https://gist.github.com/5834862.git

change https:// to git@ and /****.git to :****.git

therefore in this case

git clone git@gist.github.com:5834862.git

+12
Aug 2 '13 at 15:09
source share

The drop-down list on gist pages now has built-in / Share / Clone HTTPS / Clone SSH options:
gist dropdown
which show a non-obvious trick omit the username:

  • Clone HTTPS:
    https://gist.github.com/b6f4a53fac485f75afb9150d03efb2f6.git
    Works for me with or without .git , and with or without a username: https://gist.github.com/cben/b6f4a53fac485f75afb9150d03efb2f6 (as usual on github, the canonical view URL works

  • Clone SSH:
    git@gist.github.com:b6f4a53fac485f75afb9150d03efb2f6.git
    AKA
    ssh://git@gist.github.com/b6f4a53fac485f75afb9150d03efb2f6.git
    Works for me with or without .git , but does not work with username.




I have included github 2FA, which makes HTTPS painful, so I always want SSH; the following ~/.gitconfig translates all gists to push:

 [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/ 

And for regular (unnecessary) repositions:

 [url "ssh://git@github.com/"] pushInsteadOf = https://github.com/ 
+5
Nov 22 '16 at 13:48
source share

If you want, you can grab this script and put it somewhere in your $PATH . Once this is done, you can do the following:

  • Using HTTPS clone any text from gist.github.com (or if you already have the cloned meaning, go to the next step)
  • From anywhere in the gist git directory tree, run the command
 git-change-url --to-ssh 

Now, provided that your public key is uploaded to your github account (it must be specified here ), you should be able to work with gist via SSH , without having to enter your github credentials.

Much less error than manually editing git configuration files.

Ps: If you find any errors in the script or make any additions, feel free to fork: D

+2
Apr 27 '14 at 22:38
source share

Change https:// to ssh://git@ should do the trick, i.e. change

 https://gist.github.com/donatello/5834862 

to

 ssh://git@gist.github.com/donatello/5834862 

therefore git clone ssh://git@gist.github.com/... should clone the project (if you have already added the SSH key to Github)

In my personal opinion, the white paper is unclear about SSH.

0
Aug 08 '16 at 2:24
source share



All Articles