Skip to content

Instantly share code, notes, and snippets.

@Rarst
Created March 3, 2020 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rarst/ebd43af5e2d76bdaf180c7dd76f0fb28 to your computer and use it in GitHub Desktop.
Save Rarst/ebd43af5e2d76bdaf180c7dd76f0fb28 to your computer and use it in GitHub Desktop.
Find and garbage collect all Git repositories in path `php git-gc.php /path/to/walk`.
<?php
declare( strict_types=1 );
$path = $argv[1];
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $path ),
RecursiveIteratorIterator::SELF_FIRST
);
/** @var SplFileInfo $file */
foreach ( $iterator as $file ) {
if ( $file->isDir() && '.git' === $file->getBasename() ) {
echo $file->getPath() . "\n";
exec( "cd {$file->getPath()} && git gc --aggressive" );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment