Skip to content

Instantly share code, notes, and snippets.

@spudfkc
Last active March 26, 2017 09:22
Show Gist options
  • Save spudfkc/fcd53959cd451f8f016f to your computer and use it in GitHub Desktop.
Save spudfkc/fcd53959cd451f8f016f to your computer and use it in GitHub Desktop.
Update all git repos in current directory
#!/usr/bin/env python
# pre-req: pip install gitpython
import os
from git import *
from multiprocessing import Pool
def git_remote_update(repodir):
print ''.join(['Creating Repo at ', repodir])
repo = Repo(repodir)
if repo.is_dirty():
print ''.join(['repo: ', repodir, ' is dirty - skipping update'])
return
try:
if repo.heads.master:
repo.heads.master.checkout()
except AttributeError as e:
pass
try:
if repo.heads.air:
repo.heads.air.checkout()
except AttributeError as e:
pass
origin = repo.remotes.origin
origin.fetch()
print 'fetch\'d'
origin.pull()
print 'pull\'d'
print ''.join(['updated: ', repodir])
cwd = os.getcwd()
dirs = []
for root, subdirs, files in os.walk(cwd):
for subdir in subdirs:
try:
subdirpath = os.path.join(root, subdir)
if subdirpath.endswith('.git'):
print subdirpath
dirs.append(subdirpath)
except OSError as e:
pass
pool = Pool(10)
pool.map(git_remote_update, dirs)
print 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment