2020年8月21日 / 80次阅读
Git
问题场景:我们建立了很多分支,pull到远端origin,然后有些分支不需要了,就用git push origin :<branch_name>删除了远端origin的一些分支,但是这些分支本地还存在。存在是合理的,git给你保存了这个版本,以防止哪一天你还想把这个版本的代码找回来。不过,我们也有希望能够删除这些本地存放的已经被删除的远端分支。
$ git remote show origin,能够看到类似如下的信息:
* remote origin
Fetch URL: git@hdt.gitlab.com:engine/H2.git
Push URL: git@hdt.gitlab.com:engine/H2.git
HEAD branch: master
Remote branches:
H2-Doc tracked
develop tracked
feature/test new (next fetch will store in remotes/origin)
feature/testpush new (next fetch will store in remotes/origin)
feature_ai tracked
feature_lyp tracked
master tracked
refs/remotes/origin/13123123 stale (use 'git remote prune' to remove)
refs/remotes/origin/LogModModify stale (use 'git remote prune' to remove)
refs/remotes/origin/RequestModVideo stale (use 'git remote prune' to remove)
refs/remotes/origin/feature stale (use 'git remote prune' to remove)
refs/remotes/origin/test-1111 stale (use 'git remote prune' to remove)
refs/remotes/origin/test/test stale (use 'git remote prune' to remove)
video tracked
Local branches configured for 'git pull':
develop merges with remote develop
master merges with remote master
Local refs configured for 'git push':
develop pushes to develop (local out of date)
master pushes to master (up to date)
git已经告诉你了,这些branch已经处于stale(不新鲜)的zhuangtai9,请用git remote prune命令来删除。
$ git remote show origin
* remote origin
Fetch URL: https://github.com/xinlin-z/maily
Push URL: https://github.com/xinlin-z/maily
HEAD branch: master
Remote branches:
master tracked
refs/remotes/origin/dev stale (use 'git remote prune' to remove)
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
$ git remote prune origin
Pruning origin
URL: https://github.com/xinlin-z/maily
* [pruned] origin/dev
这样就清爽了:
$ git remote show origin
* remote origin
Fetch URL: https://github.com/xinlin-z/maily
Push URL: https://github.com/xinlin-z/maily
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
$
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
本文链接:https://www.maixj.net/ict/git-remote-prune-23883
©Copyright 麦新杰 Since 2014 云上小悟独立博客版权所有 备案号:苏ICP备14045477号-1。云上小悟网站部分内容来源于网络,转载目的是为了整合信息,收藏学习,服务大家,有些转载内容也难以判断是否有侵权问题,如果侵犯了您的权益,请及时联系站长,我会立即删除。