Created
January 9, 2025 17:15
-
-
Save nuric/7bf1bb1ded2c1dea7624f4e036dbe138 to your computer and use it in GitHub Desktop.
Garbage collect Git folders
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
#!/bin/bash | |
# Specify your home directory path (adjust if needed): | |
home_dir="/home/$USER" | |
# Find all directories containing a .git directory within your home directory: | |
git_dirs=$(find "$home_dir" -name '.git' -type d -print0 | xargs -0 -n1 dirname) | |
# Iterate through each Git directory and run git gc: | |
for git_dir in $git_dirs; do | |
echo "Running git gc in $git_dir..." | |
cd "$git_dir" || continue # Skip if directory cannot be accessed | |
git gc | |
done | |
echo "Git garbage collection completed in all Git directories." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment