使用git远程修剪原点,我可以删除不在远程上的本地分支。

但是我还想删除从这些远程分支创建的本地分支(检查它们是否未合并会很好)。

我该怎么做呢?


当前回答

可以配置Git在获取时自动删除对已删除的远程分支的引用:

git config --global fetch.prune true

当调用git fetch或git pull之后,对已删除的远程分支的引用将自动删除。

其他回答

不知道如何一次性完成,但是git git branch -d <branchname>只会在完全合并的情况下删除本地分支。注意小写的d。

git branch -D <branchname>(注意大写D)将删除本地分支,无论其合并状态如何。

使用GUI?手动操作,但快捷方便。

$ git gui

选择“分支->删除”。您可以使用ctrl-click(窗口)选择多个分支并删除它们。

您可以使用该命令:

git branch --merged master | grep -v "\* master" | xargs -n 1 git branch -d

Git清洁:删除已经合并的分支,包括分解命令

虽然迟到了,但是你可以使用——no-contains选项来避免在使用branch -merged时删除你的主分支

git branch --no-contains master --merged master | xargs git branch -d

我到达这个页面,寻求“如何删除不再有上游分支的本地签出分支”的答案。

我也不关心本地分支是否已经被合并,因为管道到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