Git 远程分支的删除与同步

删除远程分支命令
$ 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值