-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-cleanup.sh
More file actions
executable file
Β·43 lines (32 loc) Β· 1.01 KB
/
git-cleanup.sh
File metadata and controls
executable file
Β·43 lines (32 loc) Β· 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# Git Repository Cleanup Script
# This script cleans up your local git repository to remove deleted files
# and optimize storage space.
echo "π§Ή Starting Git Repository Cleanup..."
# Check if we're in a git repository
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo "β Error: Not in a git repository"
exit 1
fi
# Show current repository size
echo "π Current repository size:"
du -sh .git
echo ""
echo "π§ Step 1: Expiring reflog entries..."
git reflog expire --expire=now --all
git reflog expire --expire-unreachable=now --all
echo "π§ Step 2: Running aggressive garbage collection..."
git gc --prune=now --aggressive
echo "π§ Step 3: Pruning unreachable objects..."
git prune --expire=now
echo "π§ Step 4: Cleaning up remote references..."
git remote prune origin
echo "π§ Step 5: Final garbage collection..."
git gc --prune=now
echo ""
echo "π Repository size after cleanup:"
du -sh .git
echo ""
echo "β
Cleanup complete!"
echo "π Object statistics:"
git count-objects -vH