Skip to content

Instantly share code, notes, and snippets.

@pbt001
Forked from SpotlightKid/clone-gists.py
Created August 15, 2018 14:51

Revisions

  1. @SpotlightKid SpotlightKid revised this gist Nov 23, 2017. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions fix-remote-urls.sh
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,13 @@ for d in *; do
    pushd "$d"
    url="$(git remote get-url origin)"
    newurl="$(echo $url | sed -e 's|https://|git@|;s|\.com/|.com:|')"
    git remote remove origin && git remote add origin "$newurl"
    git pull origin master
    git branch --set-upstream-to=origin/master master

    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
  2. @SpotlightKid SpotlightKid revised this gist Nov 23, 2017. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions fix-remote-urls.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/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:|')"
    git remote remove origin && git remote add origin "$newurl"
    git pull origin master
    git branch --set-upstream-to=origin/master master
    popd
    fi
    done
  3. @SpotlightKid SpotlightKid revised this gist Dec 3, 2015. 1 changed file with 14 additions and 12 deletions.
    26 changes: 14 additions & 12 deletions clone-gists.py
    Original file line number Diff line number Diff line change
    @@ -8,25 +8,27 @@
    """

    import os
    import subprocess
    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:
    print("Usage: clone-gists.py <GitHub username>")
    sys.exit(1)
    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():
    if os.path.exists(os.path.join(gist['id'], '.git')):
    ret = subprocess.call(['git', 'pull'], cwd=gist['id'])
    else:
    ret = subprocess.call(['git', 'clone', gist['git_pull_url']])

    if ret != 0:
    print("***ERROR*** cloning/updating gist %s. Please check output." %
    gist['id'])
    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
  4. @SpotlightKid SpotlightKid revised this gist Dec 2, 2015. 1 changed file with 15 additions and 3 deletions.
    18 changes: 15 additions & 3 deletions clone-gists.py
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,14 @@
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    """Clone all gists of GitHub username given on the command line."""
    """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 os
    import subprocess
    import sys
    import requests
    @@ -15,6 +22,11 @@
    req = requests.get('https://api.github.com/users/%s/gists' % gh_user)

    for gist in req.json():
    ret = subprocess.call(['git', 'clone', gist['git_pull_url']])
    if os.path.exists(os.path.join(gist['id'], '.git')):
    ret = subprocess.call(['git', 'pull'], cwd=gist['id'])
    else:
    ret = subprocess.call(['git', 'clone', gist['git_pull_url']])

    if ret != 0:
    print("***ERROR*** cloning gist %s. Please check output." % gist['id'])
    print("***ERROR*** cloning/updating gist %s. Please check output." %
    gist['id'])
  5. @SpotlightKid SpotlightKid created this gist Dec 2, 2015.
    20 changes: 20 additions & 0 deletions clone-gists.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    """Clone all gists of GitHub username given on the command line."""

    import subprocess
    import sys
    import requests

    if len(sys.argv) > 1:
    gh_user = sys.argv[1]
    else:
    print("Usage: clone-gists.py <GitHub username>")
    sys.exit(1)

    req = requests.get('https://api.github.com/users/%s/gists' % gh_user)

    for gist in req.json():
    ret = subprocess.call(['git', 'clone', gist['git_pull_url']])
    if ret != 0:
    print("***ERROR*** cloning gist %s. Please check output." % gist['id'])