git-push.bat 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 Show files to be pushed
  29. echo.
  30. echo Files to be pushed:
  31. echo ========================================
  32. git diff --name-status origin/%MAIN_BRANCH%..HEAD 2>nul
  33. if errorlevel 1 (
  34. REM If remote branch doesn't exist, show all files
  35. git log --name-status --oneline HEAD 2>nul | findstr /V "^[a-f0-9]"
  36. )
  37. echo ========================================
  38. echo.
  39. REM Push to main branch
  40. git push origin %MAIN_BRANCH%
  41. if errorlevel 1 (
  42. echo.
  43. echo [ERROR] Push failed
  44. echo.
  45. pause
  46. ) else (
  47. echo.
  48. echo [OK] Push successful
  49. echo.
  50. pause
  51. )