Git: delete all branches without upstream

 

#!/usr/bin/env bash

# delete all branches without upstream
while read branch; do
    upstream=$(git rev-parse --abbrev-ref $branch@{upstream} 2>/dev/null)
    if [[ $? == 0 ]]; then
        # upstream exists
        echo $branch tracks $upstream
    else
        # no upstream --> delete
        git branch -d $branch
    fi
done < <(git for-each-ref --format='%(refname:short)' refs/heads)

 

posted @ 2022-11-09 18:41  ascertain  阅读(28)  评论(0)    收藏  举报