Skip to content

Commit

Permalink
git: Adds git-delete-merged-on-remote script, clarifies messaging for…
Browse files Browse the repository at this point in the history
… the local-branch version.
  • Loading branch information
damncabbage committed Sep 9, 2023
1 parent 9ee9e71 commit 8b762d4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/git-delete-merged-branches
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

BRANCHES=$(git branch --merged | grep -v "\*" | grep -v '^[ ]*master$')
echo "Deleting the following merged branches:"
echo "Deleting the following local merged branches:"
echo "$BRANCHES"
echo
echo "Proceed? (y/N)"
Expand Down
27 changes: 27 additions & 0 deletions bin/git-delete-merged-on-remote
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -eu

REMOTE="${1:-origin}"
TRUNK=$(git trunk)

BRANCHES=$( \
git branch --all --merged "remotes/${REMOTE}/${TRUNK}" \
| sed -e 's/^[ ]*//' \
| grep "^remotes/${REMOTE}" \
| grep --invert-match -e "\(HEAD\|^remotes/${REMOTE}/${TRUNK}$\)" \
| cut -d "/" -f 3-
)

echo "Deleting the following remote merged-to-${TRUNK} branches on ${REMOTE}:"
echo "$BRANCHES"
echo
echo "Proceed? (y/N)"

read PROMPT
if [ "$PROMPT" == "y" ]; then
echo "Deleting..."; sleep 2
echo $BRANCHES | xargs -n 1 git push --delete "${REMOTE}"
else
echo "Aborted."
fi

0 comments on commit 8b762d4

Please sign in to comment.