Skip to content

Instantly share code, notes, and snippets.

@KeyboardInterrupt
Forked from mgedmin/github_mirror.py
Created April 28, 2021 06:29
Show Gist options
  • Select an option

  • Save KeyboardInterrupt/1f84267dc524cc81ff29db5be86276cf to your computer and use it in GitHub Desktop.

Select an option

Save KeyboardInterrupt/1f84267dc524cc81ff29db5be86276cf to your computer and use it in GitHub Desktop.
Mirror all my github repositories and gists
#!/usr/bin/env python
# See http://stackoverflow.com/questions/3581031/backup-mirror-github-repositories/13917251#13917251
import os
import json
import urllib
import subprocess
os.chdir(os.path.expanduser('~/github'))
username = 'mgedmin'
url = 'https://api.github.com/users/%s/repos?per_page=100' % username
for repo in json.load(urllib.urlopen(url)):
print "+", repo['full_name']
if os.path.exists(repo['name']):
subprocess.call(['git', 'pull'], cwd=repo['name'])
else:
subprocess.call(['git', 'clone', repo['git_url']])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment