Skip to content
Merged
Changes from all commits
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
16 changes: 8 additions & 8 deletions bin/common/.local/bin/git-cleanup-branches
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

git fetch --prune &>/dev/null

for branch in $(git branch -vv | grep -o -E '^[\* ]+\S+' | tr -d '* '); do
upstream=$(git rev-parse --abbrev-ref --symbolic-full-name "${branch}@{upstream}" 2>/dev/null)
if [ -n "${upstream}" ]; then
if ! git show-ref --quiet "refs/remotes/${upstream}"; then
echo "Deleting branch '${branch}'"
git branch -D "${branch}"
# Use `git for-each-ref` to safely handle branch names with spaces and avoid
# parsing the output of `git branch`.
git for-each-ref --format='%(refname:short)\t%(upstream:short)' refs/heads |
while IFS=$'\t' read -r branch upstream; do
if [ -n "$upstream" ] && ! git show-ref --quiet "refs/remotes/$upstream"; then
echo "Deleting branch '$branch'"
git branch -D "$branch"
fi
fi
done
done
Loading