Skip to content

Instantly share code, notes, and snippets.

@javierarilos
Created September 4, 2015 10:44
Show Gist options
  • Save javierarilos/b7892636dfe151c5202e to your computer and use it in GitHub Desktop.
Save javierarilos/b7892636dfe151c5202e to your computer and use it in GitHub Desktop.
Recursively enters into a directory subdirs and does git pull --rebase
#!/usr/bin/env python3
"""
Recursively enters into a directory subdirs and does git pull --rebase
"""
import os
import sys
from subprocess import call
def ls_dirs(directory='.'):
return [os.path.join(directory, name) for name in os.listdir(directory) if os.path.isdir(os.path.join(directory, name))]
base_dir = (len(sys.argv) > 1 and sys.argv[1]) or '.'
dirs = ls_dirs(base_dir)
for dir in dirs:
os.chdir(dir)
print()
print('>>>>>>>>>>>>>>>> pulling:', dir)
result = call(['git', 'pull', '--rebase'])
if result != 0:
print('<<<<<<<<<<<<<<<< git pull was bad for:', dir)
else:
print('<<<<<<<<<<<<<<<< done:', dir)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment