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

相关推荐
stevenzqzq14 小时前
git 常用操作
大数据·git
Curvatureflight15 小时前
Git工作流最佳实践:从混乱到优雅
git
wu~97016 小时前
GitHub永不遗忘,使用git push -f来覆盖的提交依旧保留
git·github
Vermouth_0018 小时前
git clone的时候提示access denied
git
qq_4376572719 小时前
清楚本地的git并重新登录
git
jiang_changsheng19 小时前
工作流agent汇总分析 2
java·人工智能·git·python·机器学习·github·语音识别
顶点多余20 小时前
版本控制器-git
linux·git
夔曦20 小时前
Git工程日常下拉/上传完整流程(自用)
git
岱宗夫up20 小时前
GitHub Desktop如何设置中文?这不是个简单问题
git·github
岱宗夫up1 天前
.env 文件是干啥的?为什么不能提交到 Git?
大数据·git·elasticsearch·搜索引擎·gitee·github·gitcode