Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD branches cleanup script #1885

Merged
merged 4 commits into from
Sep 24, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions scripts/clean-merged-branches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh
#/ Usage: clean-merged-branches [-f]
#/ Delete merged branches from the origin remote.
#/
#/ Options:
#/ -f Really delete the branches. Without this branches are shown
#/ but nothing is deleted.
set -e

# show usage maybe
[ "$1" = "--help" ] && {
grep '^#/' <"$0"| cut -c4-
exit 0
}

# fetch and prune remote branches
git fetch origin --prune

# grab list of merged branches
branches=$(
git branch -a --merged origin/master |
grep remotes/origin/ |
grep -v /master |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This excludes remotes/origin/Gongreg/master as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix that and add a confirm prompt instead of "run this command with -f" message

grep -v 'enterprise-.*-release' |
sed 's@remotes/origin/@@'
)

# bail out with no branches
[ -z "$branches" ] && {
echo "no merged branches detected" 1>&2
exit 0
}

# delete the branches or just show what would be done without -f
if [ "$1" = -f ]; then
git push origin $(echo "$branches" | sed 's/^ */:/')
else
echo "These branches will be deleted:" 1>&2
echo "$branches"
echo "Run \`$0 -f' if you're sure."
fi