I have a git repository root at /git
There are different depth of paths, such as:
/git/project/project1/module1.git
/git/project/project1/module2.git
/git/project/project2/dev/module1.git
/git/library/libgit2.git
/git/library/jquery/jquery.git
How to I run git gc
recursively in all repos inside /git
?
I would prefer to use a shell script to iterate over the repositories: If that directory is not a valid git repository, do not run git gc
.
auto below for how to disable this behavior. Running git gc manually should only be needed when adding objects to a repository without regularly running such porcelain commands, to do a one-off repository optimization, or e.g. to clean up a suboptimal mass-import.
gc.pruneExpire. Optional variable that defaults to "2 weeks ago". It sets how long a inaccessible object will be preserved before pruning. gc.worktreePruneExpire. Optional variable that defaults to "3 months ago".
If you are working on a big project, then it is inevitable that you need to work with multiple repositories. That's why you need to sync your local code base with multiple Git remote repositories.
to automatically update all git repositories in that directory. You can mix and match bookmarks and command arguments: gitup --add ~/repos/foo ~/repos/bar gitup ~/repos/baz # update 'baz' only gitup # update 'foo' and 'bar' only gitup ~/repos/baz --update # update all three!
You could try something like:
find /git -name '*.git' -execdir sh -c 'cd {} && git gc' \;
This will find every directory matching *.git
under /git
, cd
into it, and run git gc
.
On some systems (ie. OSX) the for
loop treats spaces as delimiters, breaking directory names that contain spaces. Set IFS
to only use linebreaks \n
for this to work properly, and reset to default when done:
oldIFS=$IFS; IFS=$'\n'; for line in $(find /git -name '*.git'); do (echo $line; cd $line; git gc); done; IFS=$oldIFS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With