首页/开发/Git 与协作速查/git fetch --prune 清理远端跟踪引用
Git 基础与命令88 条

git fetch --prune 清理远端跟踪引用

删除远端已清除的本地下游引用:git fetch --prune 或 git remote prune origin;可设 fetch.prune=true 作为默认行为。

Git 与协作速查开发更新于 2026-10-12
用途清掉远端已删除分支的本地跟踪引用
写法git fetch --prune / git remote prune origin
默认化git config --global fetch.prune true

常用示例

常用示例
git fetch --prune
git remote prune origin
git branch -r
git config --global fetch.prune true
团队删除远端分支后,本地 git branch -r 仍列出旧分支时,用它恢复一致。

易错点

  • prune 只清理远端跟踪引用,不会删除你的本地分支
  • 本地仍持有旧分支的合并记录时,需要自行判断删除,工具不会代你决定

数据来源与参考

  • Git 官方文档:git-fetch(--prune)
  • Git 官方文档:git-remote(prune)
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌