Skip to content

Instantly share code, notes, and snippets.

@joneskoo
Created December 15, 2011 06:13
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save joneskoo/1480022 to your computer and use it in GitHub Desktop.
Save joneskoo/1480022 to your computer and use it in GitHub Desktop.
Clone all my gists automatically (gist backup?)
#!/usr/bin/env python
# Git clone all my gists
import json
import urllib
from subprocess import call
from urllib import urlopen
import os
USER = os.environ['USER']
u = urlopen('https://gist.github.com/api/v1/json/gists/' + USER)
gists = json.load(u)['gists']
for gist in gists:
call(['git', 'clone', 'git://gist.github.com/' + gist['repo'] + '.git'])
@endolith
Copy link

endolith commented Jun 5, 2016

This URL doesn't exist anymore

@mintern
Copy link

mintern commented Jul 6, 2016

Thanks a lot! I got it to work with a few minor tweaks:

#!/usr/bin/env python
# Git clone all my gists to current directory
# From https://gist.github.com/joneskoo/1480022

import json
import urllib
from subprocess import call
from urllib import urlopen
import os
USER = os.environ['USER'] # or edit as appropriate

u = urlopen("https://api.github.com/users/%s/gists" % USER)
gists = json.load(u)

for gist in gists:
    call(['git', 'clone', gist['git_pull_url']])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment