Skip to content

Instantly share code, notes, and snippets.

@austinmcconnell
Last active November 22, 2017 17:12
Show Gist options
  • Save austinmcconnell/fc4ed9676cbf1d0cbcca54ea565dc847 to your computer and use it in GitHub Desktop.
Save austinmcconnell/fc4ed9676cbf1d0cbcca54ea565dc847 to your computer and use it in GitHub Desktop.
Simple python script to reinitialize all git repositories nested one level under a "projects" folder. Primarily this is useful to "upgrade" global hooks in a ~/.git-templates folder as git init will not overwrite any existing file.
from pathlib import Path
import subprocess
CURRENT_DIR = Path('.')
projects = sorted([x for x in CURRENT_DIR.iterdir() if x.is_dir()])
for project in projects:
print('*' * 70)
print(f'Checking project: {project}')
print('*' * 70)
git_dir = project / '.git'
if not git_dir.exists():
print('Not a git repo. Skipping...')
continue
hooks_dir = git_dir / 'hooks'
hooks = [x for x in hooks_dir.iterdir() if x.is_file()]
for hook in hooks:
print(f'Removing hook: {hook.name}')
hook.unlink()
subprocess.run(['git', 'init'], cwd=project)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment