Reputation: 6275
Github really seems to want us to use the HTTPS protocol to use Gists, for example, they only list the HTTPS url on a Gist page - e.g. https://gist.github.com/donatello/5834862
Is it possible to clone a Gist using SSH protocol?
Upvotes: 90
Views: 54054
Reputation: 6275
Yes, it is possible:
git clone [email protected]:5834862.git
Just replace with your own Gist ID of course.
Upvotes: 134
Reputation: 151
SSH and HTTPS links to clone the gist can be copied directly through GitHub's interface, as shown by Beni Cherniavsky-Paskin's answer
However the gist is going to be put in a git directory with that ugly hash as name.
This can be avoided by specifying a directory name when cloning:
git clone [email protected]:9e7f15ae79acd6b60519ef094f669b26.git speedtest-loop
Upvotes: 0
Reputation: 10049
The dropdown on gist pages now has Embed/Share/Clone HTTPS/Clone SSH options (but the SSH option is only shown when you're logged in):
which show the non-obvious trick is omitting the user name:
Clone HTTPS:
https://gist.github.com/b6f4a53fac485f75afb9150d03efb2f6.git
Works for me with or without .git
, and with or without the username:
https://gist.github.com/cben/b6f4a53fac485f75afb9150d03efb2f6
(as usual on github, the canonical browsing URL works for git too)
Clone SSH:
[email protected]:b6f4a53fac485f75afb9150d03efb2f6.git
AKA
ssh://[email protected]/b6f4a53fac485f75afb9150d03efb2f6.git
Works for me with or without .git
, but doesn't work with username.
I enabled github 2FA which makes HTTPS painful so I always want SSH;
the following ~/.gitconfig
does the translation for all gists on push:
[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/
And for regular (non-gist) repos:
[url "ssh://[email protected]/"]
pushInsteadOf = https://github.com/
[url "ssh://[email protected]/"]
pushInsteadOf = https://bitbucket.org/
[url "ssh://[email protected]/"]
pushInsteadOf = https://gitlab.com/
P.S. a handy easy way to debug insteadOf
and pushInsteadOf
configs is run git remote -v
, it shows the effective URLs fetch/push will use.
Upvotes: 30
Reputation: 529
It is possible, Try this:
git clone git@YOURSSHHOST:YOURGISTIDHERE.git
Upvotes: -1
Reputation: 27258
In order for it to work, one gotta remove the username from the path, leaving only the hash / numbers alone.
Upvotes: 1
Reputation: 1655
Change https://
to ssh://git@
should do the trick, that is, change
https://gist.github.com/donatello/5834862
to
ssh://[email protected]/donatello/5834862
so git clone ssh://[email protected]/...
should clone the project (if you have already added SSH key on Github)
In my personal opinion, the official document is unclear about SSH.
Upvotes: 2
Reputation: 599
If you want, you could grab this script and put it somewhere in your $PATH
. Once that is done, you can do the following:
gist.github.com
using HTTPS
(or if you have an already cloned gist, just proceed to the next step)git-change-url --to-ssh
Now, provided that your public key is uploaded to your github account (it should be listed here) you should be able to work with the gist via SSH
, without having to enter your github credentials.
Much less error-prone than editing git config files by hand.
Ps: If you find any bugs in the script, or have any additions to make, feel free to fork :D
Upvotes: 2
Reputation: 4329
https://help.github.com/articles/which-remote-url-should-i-use#ssh-readwrite---gitgithubspanspancom
git@..... is the ssh protocol
when you copy the clone url for a gist it shows you the https clone url
https://gist.github.com/5834862.git
change https://
to git@
and /****.git
to :****.git
so in this case
git clone [email protected]:5834862.git
Upvotes: 17