@echo off setlocal EnableExtensions EnableDelayedExpansion where git >nul 2>nul if errorlevel 1 ( echo Git not found in PATH. exit /b 1 ) git rev-parse --is-inside-work-tree >nul 2>nul if errorlevel 1 ( echo Not a git repository. exit /b 1 ) for /f "delims=" %%b in ('git rev-parse --abbrev-ref HEAD') do set "CURRENT=%%b" echo Current branch: %CURRENT% echo. echo Merged branches: set "FOUND=" for /f "tokens=1 delims=* " %%b in ('git branch --merged HEAD') do ( set "BRANCH=%%b" if /i not "!BRANCH!"=="%CURRENT%" if /i not "!BRANCH!"=="main" if /i not "!BRANCH!"=="master" if /i not "!BRANCH!"=="develop" ( echo !BRANCH! set "FOUND=1" ) ) if not defined FOUND ( echo Nothing to delete. exit /b 0 ) echo. set /p ANSWER=Delete these merged branches? [y/N] if /i not "%ANSWER%"=="y" ( echo Cancelled. exit /b 0 ) for /f "tokens=1 delims=* " %%b in ('git branch --merged HEAD') do ( set "BRANCH=%%b" if /i not "!BRANCH!"=="%CURRENT%" if /i not "!BRANCH!"=="main" if /i not "!BRANCH!"=="master" if /i not "!BRANCH!"=="develop" ( git branch -d "!BRANCH!" if errorlevel 1 ( echo Could not delete !BRANCH!. ) else ( echo Deleted !BRANCH!. ) ) ) exit /b 0