mirror of
https://github.com/handsomezhuzhu/QQuiz.git
synced 2026-02-20 12:00:14 +00:00
📚 Add GitHub push guide and automation script
## 新增 - GITHUB_PUSH_GUIDE.md: 完整的 GitHub 推送指南 - Personal Access Token 认证 - SSH Key 配置 - 问题排查 - push_to_github.bat: 自动化推送脚本 - 一键提交并推送 - 友好的交互提示 🚀 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
214
GITHUB_PUSH_GUIDE.md
Normal file
214
GITHUB_PUSH_GUIDE.md
Normal file
@@ -0,0 +1,214 @@
|
||||
# GitHub 推送指南
|
||||
|
||||
## 方式一:使用 Personal Access Token(推荐)
|
||||
|
||||
GitHub 已不再支持密码认证,需要使用 Personal Access Token (PAT)。
|
||||
|
||||
### 步骤 1:创建 GitHub Personal Access Token
|
||||
|
||||
1. **访问 GitHub 设置**
|
||||
- 登录 GitHub: https://github.com
|
||||
- 点击右上角头像 → Settings
|
||||
- 左侧菜单选择 **Developer settings**
|
||||
- 选择 **Personal access tokens** → **Tokens (classic)**
|
||||
- 点击 **Generate new token** → **Generate new token (classic)**
|
||||
|
||||
2. **配置 Token**
|
||||
- Note: `QQuiz Deploy`
|
||||
- Expiration: 选择过期时间(建议 90 days 或 No expiration)
|
||||
- 勾选权限:
|
||||
- ✅ **repo** (完整仓库访问权限)
|
||||
- 点击 **Generate token**
|
||||
|
||||
3. **保存 Token**
|
||||
- ⚠️ **重要**:立即复制生成的 token,它只会显示一次!
|
||||
- 格式类似:`ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
|
||||
|
||||
### 步骤 2:配置 Git 凭据
|
||||
|
||||
**方式 A:使用 Git Credential Manager(推荐)**
|
||||
|
||||
```powershell
|
||||
# 配置凭据存储
|
||||
git config --global credential.helper manager-core
|
||||
|
||||
# 首次推送时会弹出窗口,输入:
|
||||
# Username: handsomezhuzhu
|
||||
# Password: 粘贴你的 Personal Access Token
|
||||
```
|
||||
|
||||
**方式 B:直接在 URL 中使用 Token**
|
||||
|
||||
```powershell
|
||||
cd E:\QQuiz
|
||||
|
||||
# 移除旧的 remote
|
||||
git remote remove origin
|
||||
|
||||
# 添加包含 token 的 remote
|
||||
git remote add origin https://ghp_YOUR_TOKEN_HERE@github.com/handsomezhuzhu/QQuiz.git
|
||||
|
||||
# 推送
|
||||
git push -u origin main
|
||||
```
|
||||
|
||||
将 `ghp_YOUR_TOKEN_HERE` 替换为你的实际 token。
|
||||
|
||||
### 步骤 3:推送到 GitHub
|
||||
|
||||
```powershell
|
||||
cd E:\QQuiz
|
||||
|
||||
# 推送代码
|
||||
git push -u origin main
|
||||
```
|
||||
|
||||
如果使用方式 A,会弹出认证窗口,输入:
|
||||
- **Username**: `handsomezhuzhu`
|
||||
- **Password**: 粘贴你的 Personal Access Token
|
||||
|
||||
---
|
||||
|
||||
## 方式二:使用 SSH Key(适合频繁推送)
|
||||
|
||||
### 步骤 1:生成 SSH Key
|
||||
|
||||
```powershell
|
||||
# 生成新的 SSH Key
|
||||
ssh-keygen -t ed25519 -C "your_email@example.com"
|
||||
|
||||
# 按提示操作:
|
||||
# - 文件位置:直接回车(使用默认)
|
||||
# - 密码:可以留空或设置密码
|
||||
```
|
||||
|
||||
### 步骤 2:添加 SSH Key 到 GitHub
|
||||
|
||||
```powershell
|
||||
# 查看公钥
|
||||
cat ~/.ssh/id_ed25519.pub
|
||||
|
||||
# 或在 Windows 上
|
||||
type %USERPROFILE%\.ssh\id_ed25519.pub
|
||||
```
|
||||
|
||||
复制输出的公钥(以 `ssh-ed25519` 开头)
|
||||
|
||||
1. 访问 GitHub Settings → SSH and GPG keys
|
||||
2. 点击 **New SSH key**
|
||||
3. Title: `QQuiz Dev PC`
|
||||
4. Key: 粘贴公钥
|
||||
5. 点击 **Add SSH key**
|
||||
|
||||
### 步骤 3:修改 Remote 为 SSH
|
||||
|
||||
```powershell
|
||||
cd E:\QQuiz
|
||||
|
||||
# 移除旧的 HTTPS remote
|
||||
git remote remove origin
|
||||
|
||||
# 添加 SSH remote
|
||||
git remote add origin git@github.com:handsomezhuzhu/QQuiz.git
|
||||
|
||||
# 推送
|
||||
git push -u origin main
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 快速推送脚本
|
||||
|
||||
创建 `push_to_github.bat`:
|
||||
|
||||
```batch
|
||||
@echo off
|
||||
echo Pushing to GitHub...
|
||||
|
||||
cd /d "%~dp0"
|
||||
|
||||
git add .
|
||||
git status
|
||||
|
||||
echo.
|
||||
set /p commit_msg="Enter commit message: "
|
||||
|
||||
git commit -m "%commit_msg%"
|
||||
git push origin main
|
||||
|
||||
echo.
|
||||
echo Done!
|
||||
pause
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 验证推送成功
|
||||
|
||||
推送成功后:
|
||||
|
||||
1. 访问:https://github.com/handsomezhuzhu/QQuiz
|
||||
2. 应该能看到所有代码文件
|
||||
3. 查看 Commits 历史
|
||||
|
||||
---
|
||||
|
||||
## 常见问题
|
||||
|
||||
### Q1: 推送失败 - Authentication failed
|
||||
|
||||
**原因**:密码认证已被 GitHub 禁用
|
||||
|
||||
**解决**:使用 Personal Access Token 或 SSH Key
|
||||
|
||||
### Q2: 推送被拒绝 - Updates were rejected
|
||||
|
||||
```
|
||||
! [rejected] main -> main (fetch first)
|
||||
```
|
||||
|
||||
**解决**:
|
||||
```powershell
|
||||
# 拉取远程更改
|
||||
git pull origin main --allow-unrelated-histories
|
||||
|
||||
# 再次推送
|
||||
git push -u origin main
|
||||
```
|
||||
|
||||
### Q3: 推送很慢
|
||||
|
||||
**解决**:配置代理(如果使用 VPN)
|
||||
```powershell
|
||||
# 设置 HTTP 代理
|
||||
git config --global http.proxy http://127.0.0.1:7890
|
||||
|
||||
# 取消代理
|
||||
git config --global --unset http.proxy
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 后续推送
|
||||
|
||||
首次推送成功后,以后只需:
|
||||
|
||||
```powershell
|
||||
cd E:\QQuiz
|
||||
|
||||
# 查看更改
|
||||
git status
|
||||
|
||||
# 添加文件
|
||||
git add .
|
||||
|
||||
# 提交
|
||||
git commit -m "your commit message"
|
||||
|
||||
# 推送
|
||||
git push
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
祝你推送成功!🚀
|
||||
83
push_to_github.bat
Normal file
83
push_to_github.bat
Normal file
@@ -0,0 +1,83 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
title QQuiz - 推送到 GitHub
|
||||
|
||||
echo.
|
||||
echo ==========================================
|
||||
echo 推送 QQuiz 到 GitHub
|
||||
echo ==========================================
|
||||
echo.
|
||||
|
||||
cd /d "%~dp0"
|
||||
|
||||
REM 检查是否有远程仓库
|
||||
git remote -v | findstr "origin" >nul
|
||||
if %errorlevel% neq 0 (
|
||||
echo [提示] 首次推送,正在配置远程仓库...
|
||||
git remote add origin https://github.com/handsomezhuzhu/QQuiz.git
|
||||
echo [完成] 远程仓库已配置
|
||||
echo.
|
||||
)
|
||||
|
||||
echo [1/4] 检查更改...
|
||||
git status
|
||||
|
||||
echo.
|
||||
echo [2/4] 添加所有更改...
|
||||
git add .
|
||||
|
||||
echo.
|
||||
set /p commit_msg="请输入提交信息 (或直接回车使用默认): "
|
||||
|
||||
if "%commit_msg%"=="" (
|
||||
set commit_msg=Update: minor changes
|
||||
)
|
||||
|
||||
echo.
|
||||
echo [3/4] 提交更改...
|
||||
git commit -m "%commit_msg%"
|
||||
|
||||
if %errorlevel% neq 0 (
|
||||
echo [提示] 没有需要提交的更改
|
||||
)
|
||||
|
||||
echo.
|
||||
echo [4/4] 推送到 GitHub...
|
||||
echo.
|
||||
echo [重要] 如果是首次推送,需要输入 GitHub 认证:
|
||||
echo Username: handsomezhuzhu
|
||||
echo Password: 使用 Personal Access Token (不是密码!)
|
||||
echo.
|
||||
echo 如何获取 Token: 参考 GITHUB_PUSH_GUIDE.md
|
||||
echo.
|
||||
pause
|
||||
|
||||
git push -u origin main
|
||||
|
||||
if %errorlevel% equ 0 (
|
||||
echo.
|
||||
echo ==========================================
|
||||
echo ✅ 推送成功!
|
||||
echo ==========================================
|
||||
echo.
|
||||
echo 访问仓库: https://github.com/handsomezhuzhu/QQuiz
|
||||
echo.
|
||||
) else (
|
||||
echo.
|
||||
echo ==========================================
|
||||
echo ❌ 推送失败!
|
||||
echo ==========================================
|
||||
echo.
|
||||
echo 可能的原因:
|
||||
echo 1. 未配置 GitHub 认证
|
||||
echo 2. Token 过期或无效
|
||||
echo 3. 网络连接问题
|
||||
echo.
|
||||
echo 解决方案:
|
||||
echo 1. 阅读 GITHUB_PUSH_GUIDE.md 配置认证
|
||||
echo 2. 确认 Personal Access Token 有效
|
||||
echo 3. 检查网络连接
|
||||
echo.
|
||||
)
|
||||
|
||||
pause
|
||||
Reference in New Issue
Block a user