-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathgit-tidy
executable file
·36 lines (29 loc) · 952 Bytes
/
git-tidy
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
#!/bin/bash
#
# Delete branches that have been merged and perform some extra cleanup.
#
# - Run cleanup:
#
# `git-tidy`
#
# ---
# Author: Nick Plekhanov, https://nikkhan.com/
# License: MIT
# https://github.com/nicksp/dotfiles
CYAN="$(tput setaf 6)"
UNDERLINE="$(tput sgr 0 1)"
RESET="$(tput sgr0)"
header() { echo -e "\n$UNDERLINE$CYAN$1$RESET\n"; }
branches() {
git branch --no-color --merged | grep -v '^*' | grep -v 'master' | grep -v 'main'
}
# Remove unreachable objects (commits, trees, blobs, etc.) from the Git object database
header "Deleting unreachable objects..."
git prune
# Delete all stale remote-tracking branches, these branches have already been
# removed from the remote repository, but are still locally available in "remotes/".
header "Deleting stale remote-tracking branches..."
git remote prune origin
header "Deleting merged branches except for 'master' and 'main'..."
branches | xargs -n 1 git branch -d
echo "Done."