Skip to content

Instantly share code, notes, and snippets.

@nuric
Created January 9, 2025 17:15
Show Gist options
  • Save nuric/7bf1bb1ded2c1dea7624f4e036dbe138 to your computer and use it in GitHub Desktop.
Save nuric/7bf1bb1ded2c1dea7624f4e036dbe138 to your computer and use it in GitHub Desktop.
Garbage collect Git folders
#!/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