I want to delete all branches that get listed in the output of ...
$ git branch
... but keeping current branch, in one step. Is th
I once created this construct for my Windows environment. Maybe it'll help someone else. During execution, the master and current branch are not deleted. All other merged branches will be deleted regardless.
@echo off
cd PATH_TO_YOUR_REPO
REM -- Variable declerations
set "textFile=tempBranchInfo.txt"
set "branchToKeep=master"
set "branchToReplaceWith="
git branch --merged > %textFile%
REM -- remove "master" from list to keep the branch
for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
set "line=%%i"
setlocal enabledelayedexpansion
>>"%textFile%" echo(!line:%branchToKeep%=%branchToReplaceWith%!
endlocal
)
REM -- execute branch delete commands
for /f "delims=" %%a in (%textFile%) do (
git branch -D %%a
)
REM -- remove temp-file with branch information inside
DEL %textFile%
REM -- show local branches after the cleaning
echo Local branches:
git branch
pause
exit