【Git】-- 解决git branch -a打印已被删除的远程分支

文章目录

  • [1. 问题](#1. 问题)
  • [2. 解决方法](#2. 解决方法)

更多Git相关知识: Git专栏

1. 问题

查看远程分支的情况,我们可以发现,部分分支已经是stale状态。stale状态的分支就是已经被我们删除了的分支,但是我们查看分支时依旧能看到这些分支。

bash 复制代码
root@VM-0-3-ubuntu:~/remote-gitcode# git branch -a
* feature-1
  feature-2
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/feature-1
  remotes/origin/feature-2
  remotes/origin/master
  remotes/origin/mater

root@VM-0-3-ubuntu:~/remote-gitcode# git remote show origin
* remote origin
  Fetch URL: git@gitee.com:pepper-cloth/remote-gitcode.git
  Push  URL: git@gitee.com:pepper-cloth/remote-gitcode.git
  HEAD branch: master
  Remote branches:
    master                        tracked
    refs/remotes/origin/dev       stale (use 'git remote prune' to remove)
    refs/remotes/origin/feature-1 stale (use 'git remote prune' to remove)
    refs/remotes/origin/feature-2 stale (use 'git remote prune' to remove)
    refs/remotes/origin/mater     stale (use 'git remote prune' to remove)
  Local branches configured for 'git pull':
    feature-2 merges with remote feature-2
    master    merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date)

2. 解决方法

git给我们也有一些如何删除的提示:

bash 复制代码
root@VM-0-3-ubuntu:~/remote-gitcode# git remote prune origin 
Pruning origin
URL: git@gitee.com:pepper-cloth/remote-gitcode.git
 * [pruned] origin/dev
 * [pruned] origin/feature-1
 * [pruned] origin/feature-2
 * [pruned] origin/mater

root@VM-0-3-ubuntu:~/remote-gitcode# git branch -a
* feature-1
  feature-2
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

此时,就可以看到这些stale状态的分支已经"被修剪"了。

但是本地的分支依旧存在,使用git branch -d 分支名删除即可。

相关推荐
小僧景贤14 小时前
【零门槛入门】嵌入式新手极简 Git 上手教程
git·固件开发·嵌入式版本管理
克里斯蒂亚诺更新15 小时前
云效和IDEA关于git的相通使用
git
Gavynlee15 小时前
Git 操作问题排查与解决方案记录(Gitee 实战)
git·elasticsearch·gitee
邪修king15 小时前
Re:Linux系统篇(十):从零上手 Git + GitHub(Ubuntu 环境实操完整版|个人代码归档必备)
linux·git·github
李可以量化15 小时前
Redis 从了解到精通(三)下:性能基准测试与量化场景性能避坑指南
redis·git·python·量化交易·qmt·ptrade
青 春 记 忆1 天前
零基础入门Python11|Git实战:为任务管理器建立版本历史
开发语言·git·vscode·python·python3.11
牢姐与蒯1 天前
Linux基础开发工具之版本控制器git
git
云原生指北1 天前
Docker Sandboxes 工作区怎么接:Direct、Clone 和它们的边界
git·docker·agent
菠萝猫yena1 天前
【git】git 命令常用组合
大数据·git·elasticsearch
Liekkas Kono1 天前
aicommits 工具接入 Codex CLI 使用
git·swhl·aicommits