使用git远程修剪原点,我可以删除不在远程上的本地分支。
但是我还想删除从这些远程分支创建的本地分支(检查它们是否未合并会很好)。
我该怎么做呢?
使用git远程修剪原点,我可以删除不在远程上的本地分支。
但是我还想删除从这些远程分支创建的本地分支(检查它们是否未合并会很好)。
我该怎么做呢?
当前回答
有一个整洁的npm包可以为你做这件事(它应该可以跨平台工作)。
使用npm Install -g git-removed-branches安装它
然后git remove -branches会显示所有过时的本地分支,然后git remove -branches -prune会删除它们。
更多信息请点击这里。
其他回答
在OS X上,支持cut -w
git branch -d $(git branch -vv | grep ': gone]' | cut -w -f 2 )
解释
删除以下分支
git branch -d ...
显示移除的分支
$ git branch -vv | grep ': gone]'
chore/TECH-456 a4bdac8ac8 [origin/TECH-456: gone] chore: syntax error
feature/TECH-678 0342f8e277 [origin/feature/TECH-678: gone] Added IsGross in new Income Details
保留分支名称
$ git branch -vv | grep ': gone]' | cut -w -f 2
chore/TECH-456
feature/TECH-678
删除远程分支:
$git remote prune origin
删除已合并的本地分支。
$git branch -D $(git branch --merged)
删除所有没有更新到master的分支
git co master && git branch | sed s/\*/\ / | xargs git branch -d 2> /dev/null
Powershell:
git branch -D (git branch --merged |% { $_.trim() } )
如果使用Windows和Powershell,您可以使用以下命令删除已合并到当前签出的分支中的所有本地分支:
git branch --merged | ? {$_[0] -ne '*'} | % {$_.trim()} | % {git branch -d $_}
解释
列出当前分支和已合并到其中的分支 过滤掉当前分支 清除git输出中每个剩余分支名称的前导或尾随空格 删除合并的本地分支
值得先运行git分支——自行合并,以确保它只会删除你希望它删除的东西。
(从http://railsware.com/blog/2014/08/11/git-housekeeping-tutorial-clean-up-outdated-branches-in-local-and-remote-repositories/移植/自动化。)