-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgit-clean-stale-branches
More file actions
33 lines (31 loc) · 908 Bytes
/
git-clean-stale-branches
File metadata and controls
33 lines (31 loc) · 908 Bytes
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
#!/bin/sh
#
# Suggested name for this script: git-clean-stale-branches
#
# This script will help to remove "stale" branches from a remote
# repository (by default the "origin" repository). Stale branches
# are any branches that does not exist in the local repository.
#
# This script should be run in the local repository. It will print
# out a git command to remove all branches from the remote repository
# that do not exist locally. If the command seems to be correct,
# you can copy and paste the command and run it, or re-run the script
# like this:
#
# git-clean-stale-branches | sh
#
IFS='
'
# Name of remote repository. Can be edited.
remote=origin
printf "git push $remote"
for i in `git branch -r | grep "^ *$remote/" | grep -v HEAD | sed "s;^ *$remote/;;"`
do
if git rev-parse -q --verify $i >/dev/null
then
nothing=
else
printf " :%s" "$i"
fi
done
printf "\n"