使用git远程修剪原点,我可以删除不在远程上的本地分支。
但是我还想删除从这些远程分支创建的本地分支(检查它们是否未合并会很好)。
我该怎么做呢?
使用git远程修剪原点,我可以删除不在远程上的本地分支。
但是我还想删除从这些远程分支创建的本地分支(检查它们是否未合并会很好)。
我该怎么做呢?
当前回答
删除所有没有更新到master的分支
git co master && git branch | sed s/\*/\ / | xargs git branch -d 2> /dev/null
其他回答
您可以使用该命令:
git branch --merged master | grep -v "\* master" | xargs -n 1 git branch -d
Git清洁:删除已经合并的分支,包括分解命令
检查目标
$(git分支| grep -Eiv“master|develop|branchYouWantToLive”);执行echo $target;完成
使用for &子命令运行
$(git分支| grep -Eiv“master|develop|branchYouWantToLive”);做git分支-D $target;完成
你可以扩展其他关于分支的东西。
我到达这个页面,寻求“如何删除不再有上游分支的本地签出分支”的答案。
我也不关心本地分支是否已经被合并,因为管道到git branch -d只会发出警告,而不是删除未合并的本地分支。
git branch -a | grep origin | tr -s ' ' | cut -d '/' -f3 | egrep -v -f /dev/fd/0 <(git branch -a | grep -v origin) | grep branch_prefix_that_I_care_about | xargs git branch -d
# translation
# git branch -a | grep origin | tr -s ' ' | cut -d '/' -f3
## this finds all remote branch names minus the "remote/origin/" part
#
# <(git branch -a | grep -v origin)
## this finds all local branch names and redirects it into the previous command
#
# egrep -v -f /dev/fd/0 STUFF
## this is doing some weird magic that I'm grokking as "take the set difference from whatever was piped in"
#
#
# overall translation: (STUFF TO CONSIDER) | egrep magic <(STUFF TO REMOVE FROM CONSIDERATION) | do cool things with resulting stuff
基于以上的答案,我想出了这个简单的解决方案:
git remote prune origin; git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d
它将列出远程跟踪分支从remote中删除的本地分支
$ git remote prune origin --dry-run
如果你想从未被跟踪的本地去引用这些本地分支
$ git remote prune origin