Git CLI Skill — How to Work
Use this skill when the user asks about Git from the command line: what changed, staging/committing, branching, push/pull, stashing, history, tags, merge/rebase, or cloning.
Your Workflow
- 1. Confirm context: Ensure Git is on PATH and the user is in (or will run commands in) a repo. If unsure, suggest
git status or run scripts/is-repo.sh from the skill directory. - Safety first: Prefer read-only commands (
git status, git diff, git log). Do not suggest destructive commands (git reset --hard, git clean -fdx, git push --force) unless the user explicitly asks and understands the risk. For recovery, use git reflog to find a commit before suggesting reset/checkout. - Give the right level of detail:
-
Quick answer: Use the Quick Reference table below and reply with the exact command(s).
-
Step-by-step or edge cases: Point to or quote from
reference/ (e.g.
reference/workflows.md,
reference/troubleshooting.md).
-
Automation / repeatable checks: Use or adapt scripts in
scripts/ and tell the user how to run them.
-
Templates (commit message, .gitignore): Use or copy from
assets/.
Quick Reference (use this first)
| Task | Command |
|---|
| State & diff | INLINECODE9 · git diff · git diff --staged · INLINECODE12 |
| Stage / unstage |
git add <path> or
git add . ·
git restore --staged <path> |
| Commit |
git commit -m "message" |
| Branch |
git branch ·
git branch -a ·
git switch -c new ·
git switch existing |
| Sync remote |
git fetch ·
git pull ·
git push -u origin <branch> then
git push |
| Stash |
git stash ·
git stash list ·
git stash apply /
git stash pop |
| History |
git log --oneline --decorate --graph -n 20 ·
git blame <file> |
| Clone / init |
git clone <url> ·
git init ·
git remote add origin <url> |
| Remotes |
git remote -v ·
git remote show origin ·
git branch -vv |
| Discard (destructive) |
git restore <file> (working tree) ·
git restore --staged <file> (unstage) |
| Amend |
git commit --amend --no-edit or
-m "message" |
| Tags |
git tag ·
git tag v1.0 ·
git push origin v1.0 or
--tags |
| Merge / rebase |
git merge <branch> ·
git rebase <branch> · conflict → fix →
git add →
git commit or
git rebase --continue |
Where to Look
| Need | Location |
|---|
| Full command list, options, examples | reference/commands.md |
| Step-by-step workflows (branch, release, conflict) |
reference/workflows.md |
| Errors, recovery, detached HEAD, .gitignore |
reference/troubleshooting.md |
| Run checks (is repo, status summary, branch info) |
scripts/ — run from repo root |
| Commit message or .gitignore template |
assets/ |
Scripts (run from repository root)
- - scripts/is-repo.sh — Exit 0 if current dir is a Git repo, else 1. Use to confirm context before suggesting commands.
- scripts/status-summary.sh — Short status + branch + last commit. Use when user asks "what’s my current state?"
- scripts/branch-list.sh — Local and remote branches with upstream. Use when user asks about branches or push target.
On Windows: run in Git Bash or WSL (e.g. bash scripts/status-summary.sh).
Assets
- - assets/commit-msg-template.txt — Template for conventional or structured commit messages; suggest when user asks for commit message format.
- assets/gitignore-common.txt — Common .gitignore patterns; suggest when user has many untracked files or asks for .gitignore examples.
When the user needs a diagram (e.g. branch/merge flow), describe it in text or point to reference; only create or reference images in assets/ if the user explicitly asks for a visual.
Git CLI 技能 — 工作方式
当用户询问有关命令行 Git 的问题时使用此技能:变更内容、暂存/提交、分支、推送/拉取、贮藏、历史记录、标签、合并/变基或克隆。
你的工作流程
- 1. 确认上下文:确保 Git 已加入 PATH 环境变量,且用户位于(或将在)仓库中执行命令。如果不确定,建议运行 git status 或从技能目录执行 scripts/is-repo.sh。
- 安全第一:优先使用只读命令(git status、git diff、git log)。除非用户明确要求并理解风险,否则不要建议破坏性命令(git reset --hard、git clean -fdx、git push --force)。对于恢复操作,在建议重置/检出前先使用 git reflog 查找提交。
- 提供适当详细程度:
-
快速回答:使用下方的快速参考表,回复确切的命令。
-
分步说明或边界情况:指向或引用
reference/ 中的内容(例如
reference/workflows.md、
reference/troubleshooting.md)。
-
自动化/可重复检查:使用或调整
scripts/ 中的脚本,并告知用户如何运行。
-
模板(提交信息、.gitignore):使用或复制
assets/ 中的内容。
快速参考(优先使用此表)
| 任务 | 命令 |
|---|
| 状态与差异 | git status · git diff · git diff --staged · git diff --stat |
| 暂存/取消暂存 |
git add <路径> 或 git add . · git restore --staged <路径> |
| 提交 | git commit -m 信息 |
| 分支 | git branch · git branch -a · git switch -c 新分支 · git switch 现有分支 |
| 同步远程 | git fetch · git pull · git push -u origin <分支> 然后 git push |
| 贮藏 | git stash · git stash list · git stash apply / git stash pop |
| 历史记录 | git log --oneline --decorate --graph -n 20 · git blame <文件> |
| 克隆/初始化 | git clone
· git init · git remote add origin |
| 远程仓库 | git remote -v · git remote show origin · git branch -vv |
| 丢弃(破坏性) | git restore <文件>(工作树) · git restore --staged <文件>(取消暂存) |
| 修改提交 | git commit --amend --no-edit 或 -m 信息 |
| 标签 | git tag · git tag v1.0 · git push origin v1.0 或 --tags |
| 合并/变基 | git merge <分支> · git rebase <分支> · 冲突 → 解决 → git add → git commit 或 git rebase --continue |
查找位置
reference/workflows.md |
| 错误、恢复、分离头指针、.gitignore | reference/troubleshooting.md |
| 运行检查(是否为仓库、状态摘要、分支信息) | scripts/ — 从仓库根目录运行 |
| 提交信息或 .gitignore 模板 | assets/ |
脚本(从仓库根目录运行)
- - scripts/is-repo.sh — 如果当前目录是 Git 仓库则退出码为 0,否则为 1。用于在建议命令前确认上下文。
- scripts/status-summary.sh — 简短状态 + 分支 + 最近提交。当用户询问我当前的状态是什么?时使用。
- scripts/branch-list.sh — 本地和远程分支及上游信息。当用户询问分支或推送目标时使用。
在 Windows 上:在 Git Bash 或 WSL 中运行(例如 bash scripts/status-summary.sh)。
资源文件
- - assets/commit-msg-template.txt — 传统或结构化提交信息的模板;当用户询问提交信息格式时建议使用。
- assets/gitignore-common.txt — 常见的 .gitignore 模式;当用户有大量未跟踪文件或询问 .gitignore 示例时建议使用。
当用户需要图表(例如分支/合并流程)时,用文字描述或指向参考文档;仅当用户明确要求可视化内容时才在 assets/ 中创建或引用图片。