【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
奇怪的点16 小时前
git clone失败
git
WaiSaa17 小时前
Ubuntu配置Git免密操作
git·ubuntu·gitee
牛奶咖啡1317 小时前
Git实践——分支管理与标签管理及git个性化配置
git·禁用 fast forward·bug分支的创建与操作·远程分支的查看与推送·拉取仓库·推送指定分支到远程仓库·标签的创建与操作
千寻girling20 小时前
五一劳动节快乐 [特殊字符][特殊字符][特殊字符]
java·c++·git·python·学习·github·php
波特率11520021 小时前
git指令学习
git·学习
Karry_66621 小时前
[特殊字符] Git 提交项目 全套命令(按顺序执行)
git
计算机安禾1 天前
【Linux从入门到精通】第39篇:版本控制Git服务器搭建——Gitea/GitLab私有化部署
linux·服务器·git
lst04261 天前
Git 巨大失误案例记录 (2026-05-01)
大数据·git·elasticsearch
donecoding1 天前
Git Worktree:一个仓库同时在多个分支工作,告别 stash 地狱
git