git fetch origin --prune doesn't delete local branches?

前端 未结 5 1302
夕颜
夕颜 2020-12-08 06:05

At one point I thought that git fetch origin --prune deleted local branches that were no longer present on the server. Somehow this is not my experience at the

5条回答
  •  孤城傲影
    2020-12-08 06:57

    The following command chain can be used to delete local branches:

    git branch --v | grep "\[gone\]" | awk '{print $1}' | xargs git branch -D
    
    • git branch --v lists the local branches verbosely
    • grep "[gone]" finds all the branches whose remote branch is gone
    • awk '{print $1}' outputs only the name of the matching local branches
    • xargs git branch -D deletes all the matching local branches

    This should work on MacOS as well as *nix environments.

提交回复
热议问题