[git] git删除远端分支

远端分支被删除或者合并后,还是可以在自己的仓库看到git的远端分支,这篇文章主要讲如何将这些分支删除。

查看分支命令

查看远端分支

$ git branch -r
  origin/10-
  origin/11-insert-longsql-slow
  origin/23-update-to-5.0.0
  origin/26-powersql-shardingrule-yyyymm
  origin/27-update-shardingrule-dependency
  origin/29-fix-no-split-column-insert
  origin/30-powersql-scripts
  origin/HEAD -> origin/develop
  origin/develop
  origin/master
$ git remote show origin
* remote origin
  Fetch URL: [email protected]:cloud-platform/powersql.git
  Push  URL: [email protected]:cloud-platform/powersql.git
  HEAD branch: develop
  Remote branches:
    10-                                                   tracked
    11-insert-longsql-slow                                tracked
    30-powersql-scripts                                   tracked
    develop                                               tracked
    master                                                tracked
    refs/remotes/origin/23-update-to-5.0.0                stale (use 'git remote prune' to remove)
    refs/remotes/origin/26-powersql-shardingrule-yyyymm   stale (use 'git remote prune' to remove)
    refs/remotes/origin/27-update-shardingrule-dependency stale (use 'git remote prune' to remove)
    refs/remotes/origin/29-fix-no-split-column-insert     stale (use 'git remote prune' to remove)
  Local branch configured for 'git pull':
    develop merges with remote develop
  Local ref configured for 'git push':
    develop pushes to develop (up to date)

其中,显示为stale的分支是可以删除的分支。

删除分支

网上很多帖子没讲清楚如何删除,只是说使用git remote prune 分支名即可。
尝试了以下命令:

$ git remote prune origin/23-update-to-5.0.0
fatal: 'origin/23-update-to-5.0.0' does not appear to be a git repository
fatal: Could not read from remote repository.

$ git remote prune origin/23-update-to-5.0.0
fatal: 'origin/23-update-to-5.0.0' does not appear to be a git repository
fatal: Could not read from remote repository.

发现无法删除。

删除远端分支

$ git remote prune origin
Pruning origin
URL: [email protected]:cloud-platform/powersql.git
 * [pruned] origin/23-update-to-5.0.0
 * [pruned] origin/26-powersql-shardingrule-yyyymm
 * [pruned] origin/27-update-shardingrule-dependency
 * [pruned] origin/29-fix-no-split-column-insert

再次查看:

$ git branch -r
  origin/10-
  origin/11-insert-longsql-slow
  origin/30-powersql-scripts
  origin/HEAD -> origin/develop
  origin/develop
  origin/master

已经被删除了。

你可能感兴趣的:(gitlab,git,git,gitlab)