git-push.bat 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. @echo off
  2. chcp 65001 >nul
  3. title Git Push
  4. cd /d "%~dp0\.."
  5. REM ========== Configure main branch name here ==========
  6. REM Leave empty to auto-detect (priority: master > main > current branch)
  7. set CONFIG_BRANCH=master
  8. REM ======================================================
  9. REM Detect main branch
  10. if "%CONFIG_BRANCH%"=="" (
  11. REM Auto-detect main branch
  12. git show-ref --verify --quiet refs/heads/master
  13. if %errorlevel% == 0 (
  14. set MAIN_BRANCH=master
  15. ) else (
  16. git show-ref --verify --quiet refs/heads/main
  17. if %errorlevel% == 0 (
  18. set MAIN_BRANCH=main
  19. ) else (
  20. REM If none found, use current branch
  21. for /f "tokens=*" %%i in ('git rev-parse --abbrev-ref HEAD') do set MAIN_BRANCH=%%i
  22. )
  23. )
  24. ) else (
  25. REM Use configured branch
  26. set MAIN_BRANCH=%CONFIG_BRANCH%
  27. )
  28. REM Push to main branch
  29. git push origin %MAIN_BRANCH%
  30. if errorlevel 1 (
  31. echo.
  32. echo [ERROR] Push failed
  33. echo.
  34. pause
  35. ) else (
  36. echo.
  37. echo [OK] Push successful
  38. echo.
  39. pause
  40. )