git-push

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

一键推送 GitHub

One-Click Push to GitHub

功能说明

Feature Description

把当前项目一键推送到 GitHub,覆盖完整生命周期:
  • 首次推送 — 新项目从零到 GitHub
  • 日常更新 — 改了文件,推一下(commit + push)
  • 版本发布 — 打 tag + 创建 Release,可附带下载文件
核心原则:安全第一。宁可多问一句,不能把不该推的东西推上去。

Push the current project to GitHub in one click, covering the full lifecycle:
  • First-time Push — New project from scratch to GitHub
  • Daily Update — Push after modifying files (commit + push)
  • Version Release — Create tag + Release, optional attached download files
Core Principle: Safety First. It's better to ask one more question than push something that shouldn't be pushed.

工作流程

Workflow

第0步:环境检查 + 模式判断

Step 0: Environment Check + Mode Determination

依次检查前置条件,任一不满足就终止并给出指引:
1. git 是否安装
  • ❌ → 提示:
    brew install git
    ,终止
  • ✅ → 继续
2. gh CLI 是否安装
  • ❌ → 提示:
    brew install gh
    ,终止
  • ✅ → 继续
3. gh 是否已登录 GitHub
  • 执行
    gh auth status
    检查
  • ❌ 未登录 → 提示:
    gh auth login
    ,终止
  • ✅ 已登录 → 记录账号名,告诉用户"当前登录账号:[xxx]",继续
4. git 用户信息是否配置
  • 执行
    git config user.name
    git config user.email
    检查
  • ❌ 未配置 → 提示用户设置:
    git config --global user.name "你的名字"
    git config --global user.email "你的邮箱"
    终止
  • ✅ 已配置 → 继续
5. 当前目录是否已是 git 仓库 → 决定走哪条路
不是 git 仓库 → 【首次推送】从第1步开始
是 git 仓库,无 remote → "本地有 git 但没关联远程"
    → 先执行第1步的大文件扫描(确保安全)
    → 再跳到第2步关联远程
是 git 仓库,有 remote → 【已有仓库】进入模式选择:
    ├── "推日常更新" → 跳到第3B步(日常更新)
    ├── "发新版本"   → 检查是否有未提交的变更
    │   ├── 有变更 → 先走第3B步,再走第4步
    │   └── 无变更 → 直接跳到第4步(只打 tag + Release)
    └── "重新来"
        → ⚠️ 警告:"这将删除所有 Git 历史记录(包括所有提交、分支、tag),不可恢复。"
        → 用户二次确认后删除 .git,从第1步开始

Check prerequisites in sequence, terminate and provide guidance if any is not met:
1. Is git installed?
  • ❌ → Prompt:
    brew install git
    , terminate
  • ✅ → Continue
2. Is gh CLI installed?
  • ❌ → Prompt:
    brew install gh
    , terminate
  • ✅ → Continue
3. Is gh logged into GitHub?
  • Execute
    gh auth status
    to check
  • ❌ Not logged in → Prompt:
    gh auth login
    , terminate
  • ✅ Logged in → Record account name, inform user "Current logged-in account: [xxx]", continue
4. Are git user configurations set?
  • Execute
    git config user.name
    and
    git config user.email
    to check
  • ❌ Not configured → Prompt user to set:
    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
    Terminate
  • ✅ Configured → Continue
5. Is the current directory already a git repository → Determines which path to take
Not a git repository → [First-time Push] Start from Step 1
Is a git repository, no remote → "Local git exists but not linked to remote"
    → First perform large file scanning in Step 1 (ensure safety)
    → Then jump to Step 2 to link remote
Is a git repository, has remote → [Existing Repository] Enter mode selection:
    ├── "Push daily update" → Jump to Step 3B (Daily Update)
    ├── "Release new version"   → Check for uncommitted changes
    │   ├── Has changes → First go through Step 3B, then Step 4
    │   └── No changes → Directly jump to Step 4 (only create tag + Release)
    └── "Restart"
        → ⚠️ Warning: "This will delete all Git history (including all commits, branches, tags), which cannot be recovered."
        → Delete .git after user's second confirmation, start from Step 1

第1步:项目扫描 + .gitignore 生成

Step 1: Project Scanning + .gitignore Generation

⚠️ 铁律:.gitignore 必须在第一次
git add
之前就位。绝不能先提交再排除——Git 历史里的大文件删不干净,会导致仓库臃肿、推送失败。
⚠️ Iron Rule: .gitignore must be in place before the first
git add
. Never commit first then exclude—large files in Git history cannot be fully deleted, leading to bloated repositories and push failures.

1.1 扫描目录大小

1.1 Scan Directory Size

du -sh
扫描所有顶级目录和文件,按大小排序。
大文件分级处理:
大小处理方式
>10MB列出,逐个问用户"要推吗?"
>50MB额外警告"较大,推送会比较慢"
单文件 >100MB必须排除,GitHub 硬限制,推不上去
展示格式(示例):
扫描发现以下内容超过 10MB:

  1. 109MB  slides/   (PPT + 大图片)
  2.  12MB  assets/   (视频文件)

⚠️ 其中 slides/ 超过 50MB,推送会很慢。
❌ 其中 recording.mp4 (150MB) 超过 GitHub 100MB 单文件限制,必须排除。

要排除哪些?(输入序号,或 "全部排除" / "全部保留")
Use
du -sh
to scan all top-level directories and files, sorted by size.
Large File Hierarchical Handling:
SizeHandling Method
>10MBList them, ask user one by one "Do you want to push this?"
>50MBAdditional warning "This is large, pushing will be slow"
Single file >100MBMust exclude, GitHub hard limit, cannot be pushed
Display Format (Example):
Scanned content exceeding 10MB:

  1. 109MB  slides/   (PPT + large images)
  2.  12MB  assets/   (video files)

⚠️ slides/ exceeds 50MB, pushing will be slow.
❌ recording.mp4 (150MB) exceeds GitHub's 100MB single file limit, must be excluded.

Which ones to exclude? (Enter serial numbers, or "exclude all" / "keep all")

1.2 敏感内容扫描(仅公开仓库)

1.2 Sensitive Content Scanning (Public Repositories Only)

如果用户选了公开仓库,额外扫描:
  • .env
    /
    .env.*
    — 环境变量/密钥
  • *secret*
    /
    *credential*
    /
    *token*
    — 密钥文件
  • *.pem
    /
    *.key
    — 证书文件
  • memory/
    /
    MEMORY.md
    — AI 工具记忆文件
  • 任何看起来像私人内容的文件
列出建议排除项,让用户逐项确认。
If user selects public repository, additionally scan:
  • .env
    /
    .env.*
    — Environment variables/keys
  • *secret*
    /
    *credential*
    /
    *token*
    — Secret files
  • *.pem
    /
    *.key
    — Certificate files
  • memory/
    /
    MEMORY.md
    — AI tool memory files
  • Any files that appear to be private content
List suggested exclusions, let user confirm item by item.

1.3 生成或更新 .gitignore

1.3 Generate or Update .gitignore

如果不存在 .gitignore:基于扫描结果生成新文件。
如果已存在 .gitignore:读取现有内容,将新增排除项合并进去,展示差异让用户确认。不覆盖用户已有的规则。
基础模板:
gitignore
undefined
If .gitignore does not exist: Generate new file based on scanning results.
If .gitignore already exists: Read existing content, merge new exclusions, show differences for user confirmation. Do not overwrite user's existing rules.
Base Template:
gitignore
undefined

macOS

macOS

.DS_Store .AppleDouble .LSOverride ._*
.DS_Store .AppleDouble .LSOverride ._*

Editor

Editor

*.swp *.swo *~ .vscode/ .idea/
*.swp *.swo *~ .vscode/ .idea/

[以下根据扫描结果动态生成]

[Dynamically generated based on scanning results below]

大文件(用户确认排除)

Large files (confirmed to exclude by user)

[路径1] [路径2]
[Path1] [Path2]

敏感内容(仅公开仓库时)

Sensitive content (only for public repositories)

[路径3]

展示给用户确认后写入文件。

---
[Path3]

Write to file after displaying to user for confirmation.

---

第2步:用户决策

Step 2: User Decision

1. 仓库名(默认:当前目录名)
2. 描述(一句话,可留空)
3. 公开 / 私有
  • 公开 → 二次确认:"公开仓库所有人可见,确认 .gitignore 已排除敏感内容?"
    • 不确认 → 回到第1.2步(敏感内容扫描)重新审查,完成后回到本步骤继续
4. 检查同名仓库
  • 执行
    gh repo view [账号]/[仓库名]
    检查
  • ❌ 不存在 → 继续
  • ✅ 已存在 → 告诉用户,问:
    • "换个名字" → 重新输入
    • "用这个已有仓库" → 跳过创建,直接关联 remote(记录仓库 URL 供第3步使用)
    • "删掉重建" → 需用户二次确认

1. Repository Name (Default: Current directory name)
2. Description (One sentence, can be left blank)
3. Public / Private
  • Public → Second confirmation: "Public repositories are visible to everyone, confirm that .gitignore has excluded sensitive content?"
    • Not confirmed → Return to Step 1.2 (sensitive content scanning) for re-review, then return to this step to continue
4. Check for Duplicate Repository Names
  • Execute
    gh repo view [account]/[repo-name]
    to check
  • ❌ Does not exist → Continue
  • ✅ Exists → Inform user, ask:
    • "Change name" → Re-enter
    • "Use this existing repository" → Skip creation, directly link remote (record repository URL for Step 3)
    • "Delete and rebuild" → Requires user's second confirmation

第3步:推送

Step 3: Push

3A. 首次推送(新项目)

3A. First-time Push (New Project)

按以下顺序严格执行:
1. git init + git branch -m main
2. git add -A
3. git commit -m "init: 初始化 [仓库名]"
4. 创建远程仓库(如果第2步中仓库不存在):
   gh repo create [仓库名] --private/--public --description "[描述]" --source=. --remote=origin
   (如果第2步中用户选了"用已有仓库",跳过创建,直接:git remote add origin [已有仓库URL])
5. git push -u origin main
Strictly execute in the following order:
1. git init + git branch -m main
2. git add -A
3. git commit -m "init: Initialize [repo-name]"
4. Create remote repository (if repository does not exist in Step 2):
   gh repo create [repo-name] --private/--public --description "[description]" --source=. --remote=origin
   (If user selected "use existing repository" in Step 2, skip creation, directly: git remote add origin [existing repo URL])
5. git push -u origin main

3B. 日常更新(已有仓库)

3B. Daily Update (Existing Repository)

1. 扫描变更:git status 查看改了什么
2. 检查新增大文件:
   - 新增文件中有 >10MB 的 → 问用户确认
   - 新增文件中有单文件 >100MB → 必须排除,加入 .gitignore
   - 如果修改了 .gitignore,确保 .gitignore 本身也在后续的 git add 范围内
3. git add -A
4. git commit -m "[根据变更内容自动生成提交信息]"
   - 提交信息规则:简洁明了,一句话概括主要变更
   - 示例:"update: 新增用户模块 + 修复登录 bug"
5. git push
1. Scan changes: git status to check what was modified
2. Check newly added large files:
   - New files >10MB → Ask user for confirmation
   - Single new file >100MB → Must exclude, add to .gitignore
   - If .gitignore is modified, ensure .gitignore itself is included in subsequent git add
3. git add -A
4. git commit -m "[Automatically generate commit message based on changes]"
   - Commit message rule: Concise, one sentence summarizing main changes
   - Example: "update: Add user module + fix login bug"
5. git push

推送失败处理

Push Failure Handling

错误原因处理
rejected (fetch first)
non-fast-forward
远程有本地没有的提交默认执行
git pull --rebase
后重试
仍然失败 / 远程有冲突历史不兼容问用户"是否强制覆盖远程?" ⚠️ 告知:"这将覆盖远程所有内容,仅在确认远程内容可以丢弃时使用"→
git push --force
超时/卡住网络或仓库太大检查仓库大小,建议排除大文件后重试
认证失败token 过期提示
gh auth login
file exceeds 100MB
单文件超限提示具体文件名,加入 .gitignore,重新提交推送
git add
git commit
失败
文件异常/配置缺失显示错误信息,引导用户排查

ErrorCauseHandling
rejected (fetch first)
or
non-fast-forward
Remote has commits not present locallyDefault to execute
git pull --rebase
then retry
Still failed / Remote conflictsIncompatible historyAsk user "Force overwrite remote?" ⚠️ Inform: "This will overwrite all remote content, only use if you confirm remote content can be discarded"→
git push --force
Timeout / StuckNetwork or repository too largeCheck repository size, suggest excluding large files then retry
Authentication failedToken expiredPrompt
gh auth login
file exceeds 100MB
Single file exceeds limitPrompt specific file name, add to .gitignore, re-commit and push
git add
or
git commit
failed
File exception / Missing configurationDisplay error message, guide user to troubleshoot

第4步:可选 — 版本发布(Release)

Step 4: Optional — Version Release

触发时机

Trigger Timing

  • 首次推送后,主动问一次"需要打版本吗?"
  • 日常更新后,不主动问(避免打扰)
  • 用户主动说"发版本"、"打 release"、"打 tag"
  • After first-time push, actively ask once "Need to create a version?"
  • After daily update, do not actively ask (avoid disturbance)
  • User actively says "release version", "create release", "create tag"

流程

Process

1. 确定版本号
读取当前已有的 tag(git tag --sort=-v:refname | head -5)

├── 没有任何 tag → 建议 v0.1.0
└── 已有 tag → 显示最近的版本,建议下一个(默认 minor +1)
    - v0.1.0 → 建议 v0.2.0
    - v1.2.3 → 建议 v1.3.0
    - 用户可自定义输入任意版本号

版本号说明(供用户参考):
- v0.1.0 → v0.2.0  小更新(加了功能、改了内容)
- v0.2.0 → v1.0.0  大里程碑(首次正式发布、重大重构)
- v1.0.0 → v1.0.1  修修补补(修了个 bug)
2. Release 说明
  • 自动读取自上个 tag 以来的 commit 记录(
    git log [上个tag]..HEAD --oneline
  • 生成变更摘要,让用户确认或修改
  • 如果是第一个版本(无历史 tag),用所有 commit 生成摘要
3. 是否附带下载文件
需要附带可下载文件吗?(如 App 安装包、工具压缩包等)

├── 不需要 → 只打 tag + 创建 Release 页面
└── 需要 → 用户提供文件路径
    └── 检查文件是否存在 → 不存在则提示重新输入
4. 执行
git tag [version]
git push origin [version]
gh release create [version] --title "[仓库名] [version]" --notes "[Release 说明]"
1. Determine Version Number
Read existing tags (git tag --sort=-v:refname | head -5)

├── No tags → Suggest v0.1.0
└── Has tags → Show latest version, suggest next one (default minor +1)
    - v0.1.0 → Suggest v0.2.0
    - v1.2.3 → Suggest v1.3.0
    - User can customize any version number

Version Number Explanation (for user reference):
- v0.1.0 → v0.2.0  Minor update (added features, modified content)
- v0.2.0 → v1.0.0  Major milestone (first official release, major refactoring)
- v1.0.0 → v1.0.1  Bug fixes (fixed a bug)
2. Release Notes
  • Automatically read commit records since last tag (
    git log [last tag]..HEAD --oneline
    )
  • Generate change summary, let user confirm or modify
  • If it's the first version (no historical tags), use all commits to generate summary
3. Attach Download Files?
Need to attach downloadable files? (e.g., App installation package, tool zip package, etc.)

├── No → Only create tag + Release page
└── Yes → User provides file path
    └── Check if file exists → Prompt re-entry if not exists
4. Execution
git tag [version]
git push origin [version]
gh release create [version] --title "[repo-name] [version]" --notes "[Release Notes]"

如果有附件:

If there are attachments:

gh release upload [version] [文件路径]

**Release 失败处理:**
- tag 已存在 → 提示用户"这个版本号已被使用",让用户换一个
- 附件文件不存在 → 提示重新输入路径
- 其他错误 → 显示错误信息

---
gh release upload [version] [file path]

**Release Failure Handling:**
- Tag already exists → Prompt user "This version number is already in use", let user change it
- Attachment file does not exist → Prompt re-entry of path
- Other errors → Display error message

---

完成输出

Completion Output

✅ 推送完成!

- 仓库:[URL]
- 可见性:私有 / 公开
- 文件数:[N] 个
- 仓库大小:[X]
- 排除项:[列出被 .gitignore 排除的内容]
- Release:[版本号 + URL] / 未创建

✅ Push completed!

- Repository: [URL]
- Visibility: Private / Public
- Number of files: [N]
- Repository size: [X]
- Exclusions: [List content excluded by .gitignore]
- Release: [Version number + URL] / Not created

核心原则

Core Principles

1. 扫描先于一切

1. Scanning Comes First

.gitignore 在第一次
git add
之前就位。大文件一旦进入 Git 历史,即使后来删除,仓库体积也不会缩小,会导致推送失败或极慢。已有 git 但未关联远程的项目,也要先扫描再推送。
.gitignore must be in place before the first
git add
. Once large files enter Git history, even if deleted later, repository size won't shrink, leading to push failures or extreme slowness. For projects with local git but no remote link, scan first then push.

2. 大文件主动拦截

2. Proactively Block Large Files

10MB 以上主动问用户。50MB 以上警告慢,100MB 单文件是 GitHub 硬限制必须排除。日常更新时也要检查新增文件大小。
Proactively ask user for files over 10MB. Warn about slowness for files over 50MB, single files over 100MB are GitHub's hard limit and must be excluded. Check newly added file sizes during daily updates as well.

3. 公开仓库双重检查

3. Double Check for Public Repositories

公开仓库额外扫描敏感内容(密钥、AI 记忆文件、私人文档),并在推送前二次确认。
Public repositories additionally scan sensitive content (keys, AI memory files, private documents), and require second confirmation before pushing.

4. 不破坏已有内容

4. Do Not Destroy Existing Content

如果项目已有 .git 或 .gitignore,默认不覆盖,先问用户。删除 .git 等破坏性操作必须明确警告后果并二次确认。
If project already has .git or .gitignore, do not overwrite by default, ask user first. Destructive operations like deleting .git must clearly warn of consequences and require second confirmation.

5. 每一步可中断

5. Interruptible at Every Step

用户随时可以说"停"或"回到上一步"。不要一口气跑完不给用户反应的机会。
User can say "stop" or "go back to previous step" at any time. Don't run through all steps without giving user a chance to react.

6. 日常更新要轻

6. Lightweight for Daily Updates

日常更新不问 Release、不问仓库名、不重新扫描全项目。只检查新增大文件,commit + push,快进快出。

Daily updates do not ask about Release, repository name, or re-scan the entire project. Only check newly added large files, commit + push, quick in and out.

使用示例

Usage Examples

场景1:新项目首次推送

Scenario 1: First-time Push for New Project

用户:帮我推到 GitHub

Skill:
→ 检查环境:git ✅ gh ✅ 已登录 ✅ git 用户已配置 ✅ 不是 git 仓库
→ 扫描项目...发现超过 10MB 的内容:
  - 85MB slides/ → 用户确认排除
  - 15MB images/ → 用户确认保留
→ 生成 .gitignore,用户确认
→ 仓库名:my-project,私有
→ 初始化 + 推送成功
→ "需要打 Release 吗?" → 跳过
→ ✅ 完成
User: Help me push to GitHub

Skill:
→ Check environment: git ✅ gh ✅ Logged in ✅ git user configured ✅ Not a git repository
→ Scan project...Found content exceeding 10MB:
  - 85MB slides/ → User confirms exclusion
  - 15MB images/ → User confirms retention
→ Generate .gitignore, user confirms
→ Repository name: my-project, private
→ Initialize + push successfully
→ "Need to create a Release?" → Skip
→ ✅ Completed

场景2:日常更新

Scenario 2: Daily Update

用户:推一下

Skill:
→ 检测到已关联远程仓库
→ 扫描变更:修改 3 个文件,新增 2 个文件(均 <10MB)
→ 提交信息:"update: 新增用户模块 + 更新配置文件"
→ 推送成功
→ ✅ 完成
User: Push it

Skill:
→ Detected linked remote repository
→ Scan changes: Modified 3 files, added 2 files (all <10MB)
→ Commit message: "update: Add user module + update configuration file"
→ Push successfully
→ ✅ Completed

场景3:发版本

Scenario 3: Release Version

用户:打个 release

Skill:
→ 当前最新 tag:v0.1.0
→ "建议下一个版本号 v0.2.0,可以吗?"
→ 自动生成变更摘要(基于 commit 记录)
→ "需要附带下载文件吗?" → 不需要
→ 创建 tag + Release
→ ✅ Release v0.2.0 发布成功!
User: Create a release

Skill:
→ Current latest tag: v0.1.0
→ "Suggest next version v0.2.0, okay?"
→ Automatically generate change summary (based on commit records)
→ "Need to attach download files?" → No
→ Create tag + Release
→ ✅ Release v0.2.0 created successfully!

场景4:推送时发现大文件

Scenario 4: Large File Found During Push

→ git push 失败:file recording.mp4 exceeds 100MB
→ "recording.mp4 (150MB) 超过 GitHub 限制,需要排除"
→ 加入 .gitignore,重新提交推送
→ ✅ 成功
→ git push failed: file recording.mp4 exceeds 100MB
→ "recording.mp4 (150MB) exceeds GitHub's limit, needs to be excluded"
→ Add to .gitignore, re-commit and push
→ ✅ Success

场景5:日常更新时新增大文件

Scenario 5: New Large File Added During Daily Update

用户:推一下

→ 扫描变更...发现新增文件:
  - demo.pptx (25MB)
→ "这个文件 25MB,确认要推吗?"
→ 用户确认排除 → 加入 .gitignore
→ 推送成功
→ ✅ 完成
User: Push it

→ Scan changes...Found new file:
  - demo.pptx (25MB)
→ "This file is 25MB, confirm to push?"
→ User confirms exclusion → Add to .gitignore
→ Push successfully
→ ✅ Completed

场景6:发版本但没有新变更

Scenario 6: Release Version Without New Changes

用户:打个 release

→ 当前没有未提交的变更,直接进入版本发布
→ 当前最新 tag:v0.2.0
→ "建议 v0.3.0,可以吗?"
→ 用户自定义输入 v1.0.0
→ 生成变更摘要 + 创建 Release
→ ✅ Release v1.0.0 发布成功!
User: Create a release

→ No uncommitted changes currently, directly enter version release
→ Current latest tag: v0.2.0
→ "Suggest v0.3.0, okay?"
→ User customizes input v1.0.0
→ Generate change summary + create Release
→ ✅ Release v1.0.0 created successfully!