Files
assist/test_git_push.bat

80 lines
1.5 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
echo ========================================
echo Git推送测试脚本
echo ========================================
echo.
:: 检查Git状态
echo [1] 检查Git状态...
git status --porcelain >nul 2>&1
if %errorlevel% neq 0 (
echo Git未初始化
pause
exit /b 1
)
echo Git状态正常
echo.
:: 获取当前分支
echo [2] 获取当前分支...
set current_branch=
for /f "tokens=*" %%b in ('git branch --show-current 2^>nul') do set current_branch=%%b
if "!current_branch!"=="" (
echo 无法获取当前分支使用默认分支main
set current_branch=main
) else (
echo 当前分支: !current_branch!
)
echo.
:: 检查远程仓库
echo [3] 检查远程仓库...
git remote -v
if %errorlevel% neq 0 (
echo 未配置远程仓库
pause
exit /b 1
)
echo.
:: 尝试推送
echo [4] 尝试推送到远程...
echo 分支: !current_branch!
echo.
git push origin !current_branch! 2>&1
if %errorlevel% equ 0 (
echo.
echo 推送成功!
) else (
echo.
echo 推送失败
echo.
echo 可能的原因:
echo 1. 远程分支不存在,尝试设置上游...
git push -u origin !current_branch! 2>&1
if %errorlevel% equ 0 (
echo 推送成功(已设置上游)!
) else (
echo 推送仍然失败
echo.
echo 请检查:
echo - 网络连接
echo - 认证配置SSH密钥或Token
echo - 远程仓库地址
pause
exit /b 1
)
)
echo.
echo ========================================
echo 测试完成
echo ========================================
pause