[英]How do I delete remote branches without a local tracking branch?
How can I delete all remote branches without a local tracking branch?如何在没有本地跟踪分支的情况下删除所有远程分支?
I have about 30 remote branches without local branches (that were deleted) and 20 local branches that track to a remote.我有大约 30 个没有本地分支(已删除)的远程分支和 20 个跟踪到远程的本地分支。
I kind find several posts on how to do the opposite.我找到了几篇关于如何做相反事情的帖子。
EDIT: Looking for a one-liner to solve this so that I don't manually have to delete these branches one-by-one.编辑:寻找一个单线来解决这个问题,这样我就不必手动逐个删除这些分支。
branch_not_delete=( "master" "develop")
for branch in `git for-each-ref refs/remotes/origin --format '%(refname:short)' | grep -v HEAD`; do
branch_name="$(gawk '{gsub("origin/", "");print}' <<< $branch)"
local_exists="$(git rev-parse --verify $branch_name 2> /dev/null)"
if [[ -z "${local_exists// }" ]]; then
if ! [[ " ${branch_not_delete[*]} " == *" $branch_name "* ]]; then
read -p "Would you like to delete $branch_name (yes/no) [no]: " yesno
yesno=${yesno:-no}
if [[ "$yesno" == "yes" ]]; then
git push origin :$branch_name
fi
fi
fi
done
Modified from https://stackoverflow.com/a/38776671/5399371修改自https://stackoverflow.com/a/38776671/5399371
Updated with @torek's nice suggestion.更新了@torek 的好建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.