Git Workflow
Use this skill as the repo's routing-first local Git collaboration and recovery anchor.
The job is not to teach all of Git. The job is to:
- identify the current local Git state quickly,
- choose one safe workflow mode,
- recommend the smallest reversible fix that solves the problem,
- keep boundaries to review, debugging, planning, and hosted PR workflows explicit.
Read these references when the case gets sharp-edged or the user needs more than the brief:
- references/collaboration-boundaries.md
- references/mode-selection-and-command-packets.md
- references/recovery-patterns.md
If the main need is:
- reviewing a diff for correctness, architecture, or security → route to
code-review
- reproducing or diagnosing a bug/regression → route to
debugging
- planning tasks, acceptance criteria, or sprint slices → route to
task-planning
- Aider 기반 AI pair-programming 편집 루프 운영 → route to
aider-cli-workflow
- hosted PR lifecycle, branch protection, reviewers, labels, or repo settings → use a dedicated PR/repo-management workflow
When to use this skill
- Create, rename, or clean up a branch before coding or review
- Stage changes selectively and shape reviewable commits
- Decide whether to merge or rebase onto an updated base branch
- Resolve merge/rebase conflicts safely
- Push a branch, set upstream, or update rewritten history with
--force-with-lease
- Recover from a bad reset, wrong-branch commit, detached HEAD, dropped commit, or messy rebase
- Prepare a clean diff before a later PR or review step
When not to use this skill
- The real question is whether the code or architecture is good
- The real question is how to split or sequence the work
- The real question is root cause, not Git mechanics
- The real question is hosted-service workflow instead of local repository state
- The user wants a giant Git tutorial instead of the next safe move
Instructions
Step 1: Normalize the local Git intake
Classify the request before suggesting commands.
git_intake:
current_goal: branch-setup | commit-shaping | sync-with-base | conflict-resolution | push-safety | undo-recovery | history-inspection | unknown
branch_state: clean | has-unstaged-changes | staged-only | ahead-of-origin | behind-origin | diverged | detached-head | unknown
collaboration_risk: solo-branch | shared-branch | unknown
remote_context: no-remote | origin-only | fork-plus-upstream | unknown
trigger_event:
- need-clean-commits
- rebased-branch
- merge-conflict
- wrong-branch-commit
- accidental-reset
- rejected-push
- lost-commit
- prepare-for-review
- sync-main
- unclear
preferred_history: keep-linear | preserve-merge-context | unknown
confidence: high | medium | low
If the packet is incomplete, choose the safest reasonable next move and state the assumptions.
Step 2: Choose one primary workflow mode
Pick exactly one mode:
- branch-and-stage hygiene — branch creation/switching, staging, stash-or-clean decisions
- commit-shaping — amend, fixup, reword, interactive rebase, cleaner review units
- sync-with-base — fetch + merge/rebase choice when the branch must catch up
- conflict-resolution — merge/rebase already produced conflicts; the next safe loop matters most
- push-safety — upstream setup, rejected pushes, diverged branches, rewrite-safe pushes
- undo-and-recovery — reset/rebase/amend/checkout/branch deletion went sideways; rescue first
Step 3: Use the safety ladder
Always prefer these checks before irreversible actions:
git status
git branch --show-current
git log --oneline --decorate -5
Core rules:
- Prefer
git add -p or explicit staging when commit boundaries matter.
- Prefer amend or interactive rebase only on local or safely rewritable history.
- Prefer rebase when the branch is mostly yours and a cleaner review history helps.
- Prefer merge when the branch is shared or preserving integration context matters more than linear history.
- Prefer
git push --force-with-lease, never raw --force, after intentional history rewrites.
- Prefer
git revert over reset --hard when the bad commit is already shared.
- Prefer
git reflog and a rescue branch before panic cleanup.
Step 4: Apply the decision ladder
Use these callouts explicitly:
Merge vs rebase
- Use rebase when rewrite risk is low and reviewable linear history matters.
- Use merge when the branch is shared, integration context matters, or rewrite risk is not worth it.
Revert vs reset
- Use revert for collaborative undo on already-pushed history.
- Use reset only when rewriting local history intentionally.
- Use restore / checkout of files when the worktree/index needs repair more than the branch history.
Normal push vs --force-with-lease
- Use normal push when history was not rewritten.
- Use
--force-with-lease after rebase, amend, squash, or another intentional rewrite.
- If the branch may be shared and the remote state is unclear, stop and name the collaboration risk.
Step 5: Build the Git Workflow Brief
Return this exact structure:
# Git Workflow Brief
## Recommended mode
- Mode: branch-and-stage hygiene | commit-shaping | sync-with-base | conflict-resolution | push-safety | undo-and-recovery
- Why this mode fits: ...
## Current state
- Branch: ...
- Worktree / index state: ...
- Remote context: ...
- Collaboration risk: solo-branch | shared-branch | unknown
- Confidence: high | medium | low
## Safest next move
1. ...
2. ...
3. ...
## Commands
```bash
...
Why this is the safe path
Watch-outs
Recovery fallback
- If this goes wrong, use ...
Adjacent handoff
- Use
code-review when ...
- Use
debugging when ...
- Use
task-planning when ...
### Step 6: Use concise mode packets
- **branch-and-stage hygiene** — branch name, dirty/clean state, selective staging, stash only when it lowers risk
- **commit-shaping** — reviewable commit units, amend/fixup/rebase only when rewrite is safe
- **sync-with-base** — fetch first, decide merge vs rebase explicitly, name rewrite risk before starting
- **conflict-resolution** — inspect → resolve → `git add` → continue/commit, with `abort` as the calm fallback
- **push-safety** — distinguish upstream creation, normal push, rejected push, and rewritten-history push
- **undo-and-recovery** — identify what moved, inspect `reflog`, create a rescue branch, prefer reversible steps first
Use the detailed command packets in [references/mode-selection-and-command-packets.md](references/mode-selection-and-command-packets.md) when you need the expanded workflow.
### Step 7: Keep boundaries sharp
Before finalizing:
- Do **not** turn this into a hosted PR tutorial.
- Do **not** pretend every branch should be rebased.
- Do **not** recommend `reset --hard` casually without naming the data-loss risk.
- Do **not** hide the solo-vs-shared branch distinction.
- Do **not** drift into code-review judgment, root-cause analysis, or backlog design.
## Output format
Always return a compact **Git Workflow Brief**, not a giant command dump.
Required qualities:
- choose one mode
- state the collaboration risk
- prefer the safest reversible path that solves the current problem
- make rewrite risk explicit
- include a recovery fallback when the commands have teeth
- keep routing boundaries to review, debugging, planning, and hosted PR workflows visible
## Examples
### Example 1: rebased branch needs safe push
**Input**
> I rebased my feature branch onto main and now I need to push it without overwriting teammates.
**Output sketch**
- Mode: `push-safety`
- State whether the branch looks solo or shared
- Recommend `git push --force-with-lease origin <branch>` only if rewrite is expected
- Watch-out warns against raw `--force`
### Example 2: clean up local commits before review
**Input**
> Help me turn these messy local commits into something clean before review.
**Output sketch**
- Mode: `commit-shaping`
- Suggest explicit staging plus `git rebase -i` or `git commit --amend`
- Keep the goal focused on reviewable commit units, not review comments themselves
### Example 3: wrong-branch reset panic
**Input**
> I think I hard-reset the wrong branch. Can Git recover this?
**Output sketch**
- Mode: `undo-and-recovery`
- Start with `git reflog`
- Create a rescue branch from the pre-reset SHA before further cleanup
- Explain when to stop and avoid more destructive commands
### Example 4: request is really PR review
**Input**
> Review this PR and tell me if the architecture is okay.
**Output sketch**
- Route away from `git-workflow`
- Explain that local Git prep is not the main problem here
- Hand off to `code-review`
## Best practices
1. **Inspect before surgery.** Status, branch, and recent log beat guesswork.
2. **Prefer reviewable commits over giant snapshots.** Commit shape affects review quality.
3. **Treat history rewrites as collaboration decisions, not personal preferences.** Shared branches change the answer.
4. **Use `--force-with-lease`, not raw `--force`.** Rewrite safely or do not rewrite.
5. **Reach for `reflog` early in recovery.** Lost commits are often only misplaced pointers.
6. **Choose the smallest safe fix.** Not every problem needs branch surgery.
7. **Route out when the problem changes.** Review, debugging, planning, and hosted PR work stay separate.
## References
- [references/collaboration-boundaries.md](references/collaboration-boundaries.md)
- [references/mode-selection-and-command-packets.md](references/mode-selection-and-command-packets.md)
- [references/recovery-patterns.md](references/recovery-patterns.md)
- Git documentation — https://git-scm.com/docs
- GitHub Docs, *Resolving merge conflicts after a Git rebase* — https://docs.github.com/en/get-started/using-git/resolving-merge-conflicts-after-a-git-rebase
- GitLab Docs, *Resolve conflicts from the command line* — https://docs.gitlab.com/topics/git/git_rebase/#resolve-conflicts-from-the-command-line
1---2name: git-workflow3description: Route local Git work into the safest next move: branch hygiene, selective staging, commit cleanup, merge-vs-rebase choice, conflict resolution, lease-safe pushes, and recovery from resets or bad history edits. Use when the user needs help preparing a branch, cleaning up commits, syncing with an updated base, resolving local Git conflicts, pushing rewritten history safely, recovering lost commits, or getting a diff ready for review. Not for hosted PR review, repo administration, or sprint planning.4---56# Git Workflow78Use this skill as the repo's **routing-first local Git collaboration and recovery anchor**.910The job is not to teach all of Git. The job is to:11- identify the current local Git state quickly,12- choose one safe workflow mode,13- recommend the smallest reversible fix that solves the problem,14- keep boundaries to review, debugging, planning, and hosted PR workflows explicit.1516Read these references when the case gets sharp-edged or the user needs more than the brief:17- [references/collaboration-boundaries.md](references/collaboration-boundaries.md)18- [references/mode-selection-and-command-packets.md](references/mode-selection-and-command-packets.md)19- [references/recovery-patterns.md](references/recovery-patterns.md)2021If the main need is:22- **reviewing a diff for correctness, architecture, or security** → route to `code-review`23- **reproducing or diagnosing a bug/regression** → route to `debugging`24- **planning tasks, acceptance criteria, or sprint slices** → route to `task-planning`25- **Aider 기반 AI pair-programming 편집 루프 운영** → route to `aider-cli-workflow`26- **hosted PR lifecycle, branch protection, reviewers, labels, or repo settings** → use a dedicated PR/repo-management workflow2728## When to use this skill29- Create, rename, or clean up a branch before coding or review30- Stage changes selectively and shape reviewable commits31- Decide whether to merge or rebase onto an updated base branch32- Resolve merge/rebase conflicts safely33- Push a branch, set upstream, or update rewritten history with `--force-with-lease`34- Recover from a bad reset, wrong-branch commit, detached HEAD, dropped commit, or messy rebase35- Prepare a clean diff before a later PR or review step3637## When not to use this skill38- The real question is whether the code or architecture is good39- The real question is how to split or sequence the work40- The real question is root cause, not Git mechanics41- The real question is hosted-service workflow instead of local repository state42- The user wants a giant Git tutorial instead of the next safe move4344## Instructions4546### Step 1: Normalize the local Git intake47Classify the request before suggesting commands.4849```yaml50git_intake:51 current_goal: branch-setup | commit-shaping | sync-with-base | conflict-resolution | push-safety | undo-recovery | history-inspection | unknown52 branch_state: clean | has-unstaged-changes | staged-only | ahead-of-origin | behind-origin | diverged | detached-head | unknown53 collaboration_risk: solo-branch | shared-branch | unknown54 remote_context: no-remote | origin-only | fork-plus-upstream | unknown55 trigger_event:56 - need-clean-commits57 - rebased-branch58 - merge-conflict59 - wrong-branch-commit60 - accidental-reset61 - rejected-push62 - lost-commit63 - prepare-for-review64 - sync-main65 - unclear66 preferred_history: keep-linear | preserve-merge-context | unknown67 confidence: high | medium | low68```6970If the packet is incomplete, choose the safest reasonable next move and state the assumptions.7172### Step 2: Choose one primary workflow mode73Pick exactly one mode:74751. **branch-and-stage hygiene** — branch creation/switching, staging, stash-or-clean decisions762. **commit-shaping** — amend, fixup, reword, interactive rebase, cleaner review units773. **sync-with-base** — fetch + merge/rebase choice when the branch must catch up784. **conflict-resolution** — merge/rebase already produced conflicts; the next safe loop matters most795. **push-safety** — upstream setup, rejected pushes, diverged branches, rewrite-safe pushes806. **undo-and-recovery** — reset/rebase/amend/checkout/branch deletion went sideways; rescue first8182### Step 3: Use the safety ladder83Always prefer these checks before irreversible actions:84- `git status`85- `git branch --show-current`86- `git log --oneline --decorate -5`8788Core rules:89- Prefer `git add -p` or explicit staging when commit boundaries matter.90- Prefer amend or interactive rebase only on local or safely rewritable history.91- Prefer rebase when the branch is mostly yours and a cleaner review history helps.92- Prefer merge when the branch is shared or preserving integration context matters more than linear history.93- Prefer `git push --force-with-lease`, never raw `--force`, after intentional history rewrites.94- Prefer `git revert` over `reset --hard` when the bad commit is already shared.95- Prefer `git reflog` and a rescue branch before panic cleanup.9697### Step 4: Apply the decision ladder98Use these callouts explicitly:99100#### Merge vs rebase101- **Use rebase** when rewrite risk is low and reviewable linear history matters.102- **Use merge** when the branch is shared, integration context matters, or rewrite risk is not worth it.103104#### Revert vs reset105- **Use revert** for collaborative undo on already-pushed history.106- **Use reset** only when rewriting local history intentionally.107- **Use restore / checkout of files** when the worktree/index needs repair more than the branch history.108109#### Normal push vs `--force-with-lease`110- **Use normal push** when history was not rewritten.111- **Use `--force-with-lease`** after rebase, amend, squash, or another intentional rewrite.112- If the branch may be shared and the remote state is unclear, stop and name the collaboration risk.113114### Step 5: Build the Git Workflow Brief115Return this exact structure:116117```markdown118# Git Workflow Brief119120## Recommended mode121- Mode: branch-and-stage hygiene | commit-shaping | sync-with-base | conflict-resolution | push-safety | undo-and-recovery122- Why this mode fits: ...123124## Current state125- Branch: ...126- Worktree / index state: ...127- Remote context: ...128- Collaboration risk: solo-branch | shared-branch | unknown129- Confidence: high | medium | low130131## Safest next move1321. ...1332. ...1343. ...135136## Commands137```bash138...139```140141## Why this is the safe path142- ...143- ...144145## Watch-outs146- ...147- ...148149## Recovery fallback150- If this goes wrong, use ...151152## Adjacent handoff153- Use `code-review` when ...154- Use `debugging` when ...155- Use `task-planning` when ...156```157158### Step 6: Use concise mode packets159- **branch-and-stage hygiene** — branch name, dirty/clean state, selective staging, stash only when it lowers risk160- **commit-shaping** — reviewable commit units, amend/fixup/rebase only when rewrite is safe161- **sync-with-base** — fetch first, decide merge vs rebase explicitly, name rewrite risk before starting162- **conflict-resolution** — inspect → resolve → `git add` → continue/commit, with `abort` as the calm fallback163- **push-safety** — distinguish upstream creation, normal push, rejected push, and rewritten-history push164- **undo-and-recovery** — identify what moved, inspect `reflog`, create a rescue branch, prefer reversible steps first165166Use the detailed command packets in [references/mode-selection-and-command-packets.md](references/mode-selection-and-command-packets.md) when you need the expanded workflow.167168### Step 7: Keep boundaries sharp169Before finalizing:170- Do **not** turn this into a hosted PR tutorial.171- Do **not** pretend every branch should be rebased.172- Do **not** recommend `reset --hard` casually without naming the data-loss risk.173- Do **not** hide the solo-vs-shared branch distinction.174- Do **not** drift into code-review judgment, root-cause analysis, or backlog design.175176## Output format177Always return a compact **Git Workflow Brief**, not a giant command dump.178179Required qualities:180- choose one mode181- state the collaboration risk182- prefer the safest reversible path that solves the current problem183- make rewrite risk explicit184- include a recovery fallback when the commands have teeth185- keep routing boundaries to review, debugging, planning, and hosted PR workflows visible186187## Examples188189### Example 1: rebased branch needs safe push190**Input**191> I rebased my feature branch onto main and now I need to push it without overwriting teammates.192193**Output sketch**194- Mode: `push-safety`195- State whether the branch looks solo or shared196- Recommend `git push --force-with-lease origin <branch>` only if rewrite is expected197- Watch-out warns against raw `--force`198199### Example 2: clean up local commits before review200**Input**201> Help me turn these messy local commits into something clean before review.202203**Output sketch**204- Mode: `commit-shaping`205- Suggest explicit staging plus `git rebase -i` or `git commit --amend`206- Keep the goal focused on reviewable commit units, not review comments themselves207208### Example 3: wrong-branch reset panic209**Input**210> I think I hard-reset the wrong branch. Can Git recover this?211212**Output sketch**213- Mode: `undo-and-recovery`214- Start with `git reflog`215- Create a rescue branch from the pre-reset SHA before further cleanup216- Explain when to stop and avoid more destructive commands217218### Example 4: request is really PR review219**Input**220> Review this PR and tell me if the architecture is okay.221222**Output sketch**223- Route away from `git-workflow`224- Explain that local Git prep is not the main problem here225- Hand off to `code-review`226227## Best practices2281. **Inspect before surgery.** Status, branch, and recent log beat guesswork.2292. **Prefer reviewable commits over giant snapshots.** Commit shape affects review quality.2303. **Treat history rewrites as collaboration decisions, not personal preferences.** Shared branches change the answer.2314. **Use `--force-with-lease`, not raw `--force`.** Rewrite safely or do not rewrite.2325. **Reach for `reflog` early in recovery.** Lost commits are often only misplaced pointers.2336. **Choose the smallest safe fix.** Not every problem needs branch surgery.2347. **Route out when the problem changes.** Review, debugging, planning, and hosted PR work stay separate.235236## References237- [references/collaboration-boundaries.md](references/collaboration-boundaries.md)238- [references/mode-selection-and-command-packets.md](references/mode-selection-and-command-packets.md)239- [references/recovery-patterns.md](references/recovery-patterns.md)240- Git documentation — https://git-scm.com/docs241- GitHub Docs, *Resolving merge conflicts after a Git rebase* — https://docs.github.com/en/get-started/using-git/resolving-merge-conflicts-after-a-git-rebase242- GitLab Docs, *Resolve conflicts from the command line* — https://docs.gitlab.com/topics/git/git_rebase/#resolve-conflicts-from-the-command-line