在 Git 中修剪远程分支
本文将展示如何修剪(清理)在远程仓库中删除的远程跟踪分支。
例如,Alice 和 Bob 正在开发一个分支 feature/shared-branch
。Bob 创建一个拉取请求,合并 feature/shared-branch
,然后将其删除。
她在 Alice 这边执行 git pull origin feature/shared-branch
。
$ git branch -a
* feature/shared-branch
main
remotes/origin/feature/shared-branch
remotes/origin/main
$ git pull origin feature/shared-branch
fatal: couldn't find remote ref feature/shared-branch
尽管 remotes/origin/feature/shared-branch
出现在 git branch -a
下,执行 git pull origin feature/shared-branch
仍然会触发错误,因为 feature/shared-branch
已被删除远程仓库。
为了克服这个问题,Alice 应该清理 feature/shared-branch
的引用,它是 remotes/origin/feature/shared-branch
。她可能会运行 git remote prune origin
。
$ git remote prune origin
Pruning origin
URL: git@github.com:stwarts/git-demo.git
* [pruned] origin/feature/shared-branch
git remote prune origin
执行检查。远程仓库中不存在的远程跟踪分支将被删除。
feature/shared-branch
已被 Bob 删除。在 Alice 执行 git remote prune origin
后,它的远程跟踪分支 remotes/origin/feature/shared-branch
将在 Alice 机器中被删除。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布,任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站。本站所有源码与软件均为原作者提供,仅供学习和研究使用。如您对本站的相关版权有任何异议,或者认为侵犯了您的合法权益,请及时通知我们处理。