reForge-portable / runscripts /switch-branch.bat
Xeno443's picture
Updated all files
e67795a verified
raw
history blame
1.44 kB
@echo off
call environment.bat passive
pushd "%~dp0\webui"
echo Fetching latest remote branches...
git fetch --all >nul 2>&1
setlocal enabledelayedexpansion
:choose_branch
cls
set "current_branch="
for /f "delims=" %%C in ('git rev-parse --abbrev-ref HEAD 2^>nul') do set "current_branch=%%C"
if not defined current_branch (
echo Current branch: [no branch information available]
) else if /i "!current_branch!"=="HEAD" (
echo Current branch: [detached HEAD]
) else (
echo Current branch: !current_branch!
)
echo.
echo Available branches:
echo.
set idx=0
for /f "tokens=1" %%B in ('git branch -r ^| findstr /i /v "origin/HEAD"') do (
set "branchName=%%B"
set "branchName=!branchName:origin/=!"
set /a idx+=1
set "branch[!idx!]=!branchName!"
echo !idx!. !branchName!
)
echo.
echo Enter a branch number to checkout, or X to exit.
set /p choice="Choice: "
:: Exit option
if /i "%choice%"=="X" goto :end
:: Validate numeric selection
if not defined branch[%choice%] (
echo Invalid selection. Please try again.
pause
goto :choose_branch
)
set "selected=!branch[%choice%]!"
echo.
echo Switching to branch %selected% ...
git checkout %selected%
echo Pulling files ...
git pull
if %ERRORLEVEL% neq 0 (
echo Conflict detected, trying hard reset and pull ...
git reset --hard
git pull
)
:end
endlocal
popd
pause