#!/bin/bash
set -eu

if [[ $# -eq 0 ]]; then
	readonly dirlist=(.)
else
	readonly dirlist=("$@")
fi

readonly gc_flags=()

readonly origdir="$(pwd)"
for dir in "${dirlist[@]}"; do
	for repo in "$dir"/*/; do
		if [[ ! -d "$repo/.git" ]]; then
			continue
		fi

		cd "$repo"
		echo "Entering $repo..."
		git fsck --full
		git gc "${gc_flags[@]}"
		cd "$origdir"
	done
done


#!/bin/bash
set -eu

if [[ $# -eq 0 ]]; then
	readonly dirlist=(.)
else
	readonly dirlist=("$@")
fi

readonly gc_flags=(
	'--aggressive'
)

readonly origdir="$(pwd)"
for dir in "${dirlist[@]}"; do
	for repo in "$dir"/*/; do
		if [[ ! -d "$repo/.git" ]]; then
			continue
		fi

		cd "$repo"
		echo "Entering $repo..."
		git fsck --full
		git gc "${gc_flags[@]}"
		cd "$origdir"
	done
done


Add --aggressive to gc flags.
Add --aggressive to gc flags.
