删除远程分支命令
$ git push origin :remote_branch
或者
$ git push origin --delete remote_branch
删除完成后, 另一个用户使用git fetch
并不能同步获取到remote_branch 被删除
$ git fetch
执行此命令后, 没有更新提示,, 说明并无删除的信息, 但执行git pull 时, 报错.
$ git pull
Your configuration specifies to merge with the ref 'remote_branch'
from the remote, but no such ref was fetched.
原因是执行git fetch
时, 已经出错了
$ git fetch origin br03
fatal: Couldn't find remote ref br03
fatal: The remote end hung up unexpectedly
但用git branch -a
检查, 发现origin/remote_branch还在, 这说明,remotes/origin/*
这些远程跟踪分支,仅仅是远程分支的一个缓存,并且,不能通过git fetch
命令获取到分支删除的更新
执行命令
$ git remote show origin
* remote origin
Fetch URL: git@github0123:jeremy0123/fetch.git
Push URL: git@github0123:jeremy0123/fetch.git
HEAD branch: master
Remote branches:
br01-remote tracked
br02 tracked
br03-remote tracked
master tracked
refs/remotes/origin/br03 stale (use 'git remote prune' to remove)
Local branches configured for 'git pull':
br01 merges with remote br01-remote
br03 merges with remote br03
master merges with remote master
Local refs configured for 'git push':
br02 pushes to br02 (up to date)
master pushes to master (local out of date)
发现refs/remotes/origin/br03
状态是stale(陈旧的),并且后面有命令提示。
执行
$ git remote prune origin
Pruning origin
URL: git@github0123:jeremy0123/fetch.git
* [pruned] origin/br03
或者 执行
$ git fetch -p
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From git@github0123:jeremy0123/fetch.git
04a6837..d49d143 master -> origin/master
x [deleted] (none) -> origin/br03
EOF