【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 分支名删除即可。

相关推荐
vibecoding日记2 天前
为什么我就想要「线性历史 + Signed Commits」,GitHub 却把我当猴耍 🤬🎙️
git·编程工具
程序员小崔日记2 天前
如何将代码轻松上传到 Gitee?Git 使用全攻略!
git·gitee·上传
Bigger3 天前
为什么你的 Git 提交需要签名?—— Git Commit Signing 完全指南
git·开源·github
DianSan_ERP4 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
红豆子不相思4 天前
Tomcat 环境搭建与集群实战
服务器·git·tomcat
杰哥技术分享4 天前
Git 仓库迁移技术文档:从 CODING.net 迁移至腾讯云 CNB
git
梅孔立4 天前
Ansible 100 台服务器一键管控实战 进阶版
服务器·git·ansible
qq_426003965 天前
git切换当前分支到远程分支
git
ON10N5 天前
100% 纯 Vibe Coding,我是怎么用 AI 撸出一个 VS Code 插件的
git·ai编程·visual studio code