【bash】删除本地所有分支

  1. 创建 del-local-branches.sh 文件

  2. 复制下面的脚本

bash 复制代码
#!bin/bash

# 确认当前分支是否为'master'
if [ "$(git rev-parse --abbrev-ref HEAD)" != "master" ]; then
  git fetch origin && git checkout master
fi
# 遍历所有本地分支
for branch in $(git branch --format "%(refname:lstrip=-1)"); do
    # 忽略'master'分支
    if [ "$branch" != "master" ]; then
        # 强制删除分支
        git branch -D "$branch"
        echo "Deleted local branch: \033[31m$branch\033[0m(\033[32mdone\033[0m)"
    fi
done
  1. 通过命令行执行该脚本
bash 复制代码
$ sh del-local-branches.sh
相关推荐
咖啡の猫1 小时前
Shell脚本-for循环应用案例
前端·chrome
anlogic3 小时前
Java基础 8.18
java·开发语言
沐知全栈开发4 小时前
WebForms XML 文件详解
开发语言
阿巴~阿巴~5 小时前
冒泡排序算法
c语言·开发语言·算法·排序算法
看到我,请让我去学习6 小时前
QT - QT开发进阶合集
开发语言·qt
weixin_307779136 小时前
VS Code配置MinGW64编译SQLite3库
开发语言·数据库·c++·vscode·算法
励志不掉头发的内向程序员7 小时前
STL库——string(类函数学习)
开发语言·c++
一百天成为python专家7 小时前
Python循环语句 从入门到精通
开发语言·人工智能·python·opencv·支持向量机·计算机视觉
Sunhen_Qiletian7 小时前
朝花夕拾(五)--------Python 中函数、库及接口的详解
开发语言·python
hqwest8 小时前
C#WPF实战出真汁07--【系统设置】--菜品类型设置
开发语言·c#·wpf·grid设计·stackpanel布局