| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- @echo off
- chcp 65001 >nul
- title Git Push
- cd /d "%~dp0\.."
- REM ========== Configure main branch name here ==========
- REM Leave empty to auto-detect (priority: master > main > current branch)
- set CONFIG_BRANCH=master
- REM ======================================================
- REM Detect main branch
- if "%CONFIG_BRANCH%"=="" (
- REM Auto-detect main branch
- git show-ref --verify --quiet refs/heads/master
- if %errorlevel% == 0 (
- set MAIN_BRANCH=master
- ) else (
- git show-ref --verify --quiet refs/heads/main
- if %errorlevel% == 0 (
- set MAIN_BRANCH=main
- ) else (
- REM If none found, use current branch
- for /f "tokens=*" %%i in ('git rev-parse --abbrev-ref HEAD') do set MAIN_BRANCH=%%i
- )
- )
- ) else (
- REM Use configured branch
- set MAIN_BRANCH=%CONFIG_BRANCH%
- )
- REM Show files to be pushed
- echo.
- echo Files to be pushed:
- echo ========================================
- git diff --name-status origin/%MAIN_BRANCH%..HEAD 2>nul
- if errorlevel 1 (
- REM If remote branch doesn't exist, show all files
- git log --name-status --oneline HEAD 2>nul | findstr /V "^[a-f0-9]"
- )
- echo ========================================
- echo.
- REM Push to main branch
- git push origin %MAIN_BRANCH%
- if errorlevel 1 (
- echo.
- echo [ERROR] Push failed
- echo.
- pause
- ) else (
- echo.
- echo [OK] Push successful
- echo.
- pause
- )
|