1.删除远程分支
在远程下面,选择需要删除的分支,右击,选择删除
2. 删除不存在远程对应分支的本地分支
在远程上建立了一个分支feature,后来leader觉得不合理,就把远程feature分支删除,并又建立了一个feature分支,这导致我在sourceTree上无法pull到最新的版本。
也假设出现这样的情况:
- 我创建了本地分支b1并pull到远程分支
origin/b1
; - 其他人在本地使用fetch或pull创建了本地的b1分支;
- 我删除了
origin/b1
远程分支; - 其他人再次执行fetch或者pull并不会删除这个他们本地的
b1
分支,运行git branch -a
也不能看出这个branch被删除了,如何处理?
[root@test01 H2]# 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)
这时候能够看到feature是stale的,使用 git remote prune origin
可以将其从本地版本库中去除。
[root@test01 H2]# git remote prune origin
Pruning originURL: git@hdt.gitlab.com:engine/H2.git * [pruned] origin/13123123 * [pruned] origin/LogModModify * [pruned] origin/RequestModVideo * [pruned] origin/feature * [pruned] origin/test-1111 * [pruned] origin/test/test更简单的方法是使用这个命令,它在fetch之后删除掉没有与远程分支对应的本地分支:
git fetch -p
查看全部分支
[root@test01 H2]# git branch -a
* develop master remotes/origin/H2-Doc remotes/origin/HEAD -> origin/master remotes/origin/develop remotes/origin/feature_ai remotes/origin/feature_lyp remotes/origin/master remotes/origin/video可以看到feature分支已经被删除掉了
参考链接 http://blog.csdn.net/ai2000ai/article/details/45021977