Skip to content

Instantly share code, notes, and snippets.

@jdforsythe
Created September 8, 2016 18:38
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 jdforsythe/49c900e84835fb3153abd49e7d4360be to your computer and use it in GitHub Desktop.
Save jdforsythe/49c900e84835fb3153abd49e7d4360be to your computer and use it in GitHub Desktop.
Git Maintenance
#!/bin/bash
echo "Cleaning git merge conflict artifacts..."
find . -name "*.bak" | while read filename; do echo "Removing: $filename" && rm -rf "$filename"; done
echo -e "\n"
echo "Counting unreachable objects in git database..."
unreachable=$(git fsck --unreachable | wc -l)
echo "There are $unreachable unreachable objects."
if [ $unreachable -gt 0 ]; then
echo "Cleaning unreachable objects.."
git prune
fi
echo -e "\n"
echo "Packing unpacked objects..."
git repack -a -d -l
echo -e "\n"
echo "Forcing garbage collection..."
git gc --aggressive
echo -e "\n"
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment