zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Git: delete all branches without upstream

Git all delete Without upstream
2023-09-11 14:16:15 时间

 

#!/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)