-
-
Save pbt001/26f3b4eaf8dcc29d09524e20ce51a04e to your computer and use it in GitHub Desktop.
Clone all gists of GitHub username given on the command line.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""Clone all gists of GitHub user with given username. | |
Clones all gist repos into the current directory, using the gist id as the | |
directory name. If the directory already exists as a git repo, try to perform a | |
'git pull' in it. | |
""" | |
import sys | |
import requests | |
from os.path import exists, join | |
from subprocess import CalledProcessError, check_call | |
if len(sys.argv) > 1: | |
gh_user = sys.argv[1] | |
else: | |
sys.exit("Usage: clone-gists.py <GitHub username>") | |
req = requests.get('https://api.github.com/users/%s/gists' % gh_user) | |
for gist in req.json(): | |
try: | |
gid = gist['id'] | |
if exists(join(gid, '.git')): | |
check_call(['git', 'pull', '-v'], cwd=gid) | |
else: | |
check_call(['git', 'clone', gist['git_pull_url']]) | |
except CalledProcessError: | |
print("*** ERROR cloning/updating gist %s. Please check output." % gid) | |
except KeyboardInterrupt: | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# replace gist git repo remote origin https URL with SSH one. | |
# | |
for d in *; do | |
if [ -d "$d/.git" ]; then | |
pushd "$d" | |
url="$(git remote get-url origin)" | |
newurl="$(echo $url | sed -e 's|https://|git@|;s|\.com/|.com:|')" | |
if [ "x$url" != "x$newurl" ]; then | |
git remote remove origin && git remote add origin "$newurl" | |
git pull origin master | |
git branch --set-upstream-to=origin/master master | |
fi | |
popd | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment