在使用git时,有时某分支已在远程服务器删除,但本地不会同步删除,这个分支依然存在。

如下命令可以删除本地版本库上那些失效的远程追踪分支,具体用法是,假如你的远程版本库名是 origin,则使用如下命令先查看哪些分支需要清理:

$ git remote prune origin --dry-run
修剪 origin
URL:git@yuhu.github.com:yuhu-tech/grampus-contracts.git
 * [将删除] origin/cq-2021-0227_refactor
 * [将删除] origin/lichagn-feat-impl-grc20
 * [将删除] origin/lichagn-feat-impl-grc20-em20-em721
 * [将删除] origin/lichang-feat-add-some-support-for-ANT
 * [将删除] origin/lichang-feat-impl-20-and-720
 * [将删除] origin/lichang-feat-mdy-20
 * [将删除] origin/lichang-feat-mdy-20-and-721
 * [将删除] origin/litao-dev
 * [将删除] origin/runjam-v0.0.2

可以看到, 以上分支已经失效,将被删除,执行

$ git remote prune origin
修剪 origin
URL:git@yuhu.github.com:yuhu-tech/grampus-contracts.git
 * [已删除] origin/cq-2021-0227_refactor
 * [已删除] origin/lichagn-feat-impl-grc20
 * [已删除] origin/lichagn-feat-impl-grc20-em20-em721
 * [已删除] origin/lichang-feat-add-some-support-for-ANT
 * [已删除] origin/lichang-feat-impl-20-and-720
 * [已删除] origin/lichang-feat-mdy-20
 * [已删除] origin/lichang-feat-mdy-20-and-721
 * [已删除] origin/litao-dev
 * [已删除] origin/runjam-v0.0.2