This can save some disk space, especially if you have many large git repos on your hard drive. Meant to be run from a parent directory where all code/projects are kept. Skips directories that aren't git repos.
Created
January 22, 2026 19:51
-
-
Save phette23/0f331bf18340d5622b5d4c2e60ecb89b to your computer and use it in GitHub Desktop.
recursive git garbage collection
This file contains hidden or 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 | |
| # Recursively runs 'git gc' in all git repositories starting from the current directory. | |
| import subprocess | |
| from os import walk | |
| for dirpath, dirnames, filenames in walk("."): | |
| if ".git" in dirnames: | |
| print(f"Running 'git gc' in {dirpath}") | |
| subprocess.run(["git", "-C", dirpath, "gc"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment