File: git-delete-old-branches

package info (click to toggle)
bro-aux 0.42-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 1,104 kB
  • sloc: sh: 999; ansic: 943; ruby: 71; makefile: 68; perl: 35; cpp: 26
file content (32 lines) | stat: -rwxr-xr-x 789 bytes parent folder | download | duplicates (2)
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
# ! /usr/bin/env bash
#
# Adapted from http://devblog.springest.com/a-script-to-remove-old-git-branches
#

# This has to be run from master
git checkout master

# Update our list of remotes
git fetch
git remote prune origin

# # Remove local fully merged branches
# git branch --merged master | grep -v 'master$' | xargs git branch -d

# Show remote fully merged branches
echo "The following remote branches are fully merged and will be removed:"
git branch -r --merged master | sed 's/ *origin\///' | grep '^topic/'

if [ $? != 0 ]; then
    exit 0
fi

read -p "Continue (y/n)? "

if [ "$REPLY" == "y" ]
then
   # Remove remote fully merged branches
   git branch -r --merged master | sed 's/ *origin\///' \
             | grep '^topic/' | xargs -I% git push origin :%
   echo "Done!"
fi