| name | git-workflow-and-versioning |
| description | Structure disciplined git practices for commits, branches, and history. Use when making any code change โ committing, branching, resolving conflicts, or organizing work across parallel streams. |
Git Workflow and Versioning
Overview
Git is your safety net and your documentation. Treat commits as save points, branches as isolated sandboxes, and history as a narrative that future readers will depend on. With agents generating code at high velocity, disciplined version control is what keeps changes manageable, reviewable, and reversible.
When to Use
Always. Every code change flows through git.
Branching Model
Trunk-Based Development
Keep the default branch always deployable. Work in short-lived feature branches that merge back within one to three days.
main โโโโโโโโโโโโโโโโโโโโโโโ (always deployable)
โฒ โฑ โฒ โฑ
โโโโโโฑ โโโโฑ (short-lived branches, 1-3 days)
Long-lived branches diverge, create merge conflicts, and delay integration. Prefer feature flags over long branches for incomplete features.
Branch Naming
feature/[short-description] โ feature/task-sharing
fix/[short-description] โ fix/duplicate-creation
chore/[short-description] โ chore/upgrade-deps
refactor/[short-description] โ refactor/auth-module
Commit Discipline
Atomic Commits
Each commit does one logical thing. Do not mix concerns.
Good:
a1b2c3d feat: add task creation endpoint with validation
d4e5f6g feat: add task creation form component
h7i8j9k feat: connect form to API with loading state
Bad:
x1y2z3a add task feature, fix sidebar, update deps
Commit Messages
First line: short imperative sentence explaining the intent.
Body (optional): why, not what. Include context not visible in the diff.
feat: add boundary validation to signup flow
Prevents malformed input from reaching the user service.
Uses the existing ValidationError pattern from src/lib/errors.ts.
Type Prefixes
feat โ new feature
fix โ bug fix
refactor โ restructuring without behavior change
test โ adding or updating tests
docs โ documentation only
chore โ tooling, dependencies, config
Separate Concerns
Do not combine formatting with behavior. Do not combine refactors with features. Each type of change is a separate commit โ ideally a separate PR.
Size Targets
~100 lines โ easy to review, easy to revert
~300 lines โ acceptable for one logical change
~500+ lines โ split before submitting
The Save Point Pattern
Agent makes a change
test passes? โ commit โ continue to next change
test fails? โ revert to last commit โ investigate
Repeat until feature complete.
You never lose more than one increment of work. If something goes wrong, git reset --hard HEAD returns to the last verified state.
Frame slice commit rhythm
/frame์ด ๋ง๋ implementation_plan.slices[]๊ฐ ์์ผ๋ฉด ๊ฐ slice๋ ์ปค๋ฐ ํ๋ณด ๋จ์๋ค. ํ๋ํ๊ฒ ๋ค์ ์์
์ ๋ง๊ธฐ๋ณด๋ค, slice closure ์์ ๋ง๋ค ์๋๋ฅผ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ํํ๋ค.
- currentSlice์ claim/scope/evidence๋ฅผ ํ์ธํ๋ค.
- ๊ฐ๊น์ด ๊ฒ์ฆ์ด ํต๊ณผํ๋ฉด
work_context action=commit_plan์ผ๋ก explicit auto_commit plan์ ์์ฑํ๋ค.
- plan์ ๊ฒํ ํ ๋ ํ commit entry์ primary path๊ฐ 3๊ฐ ์ด์์ด๋ฉด ํ์ผ ์๋ง ๋ณด์ง ๋ง๊ณ diff ์, layer mix, cluster/surface fan-out์ ํ์ธํ๋ค. ์์ ๋์ผ cluster ๋ณ๊ฒฝ์ warning allow๊ฐ ๊ฐ๋ฅํ์ง๋ง, ํฐ diff๋ layer-mixed ๋ณ๊ฒฝ์ logical atom ๋จ์๋ก ์ชผ๊ฐ ๋ค. test/generated/schema/package metadata๋ companion์ผ๋ก๋ง ๋ถ์ธ๋ค.
- plan์ ๊ฒํ ํ ๋ค
auto_commit action=apply๋ก ์ปค๋ฐํ๋ค.
- ์ปค๋ฐ์ ๋ฏธ๋ฃจ๋ฉด ์ด์ ๋ฅผ
work_context checkpoint์ ๋จ๊ธด๋ค.
์ด ๋ฆฌ๋ฌ์ my-pi /ship์ โcommit + verify + push๊ฐ ๊ธฐ๋ณธโ ์์น์ ๊ตฌํ ์ค slice ๋จ์๋ก ์๋น๊ธด ๊ฒ์ด๋ค. ๋ง์ง๋ง ship/final-check์์ ํ๊บผ๋ฒ์ ์ปค๋ฐ์ ๋ฐ๊ฒฌํ๋ ํ๋ฆ์ ์ ์ ๊ฒฝ๋ก๋ก ๋ณด์ง ์๋๋ค.
Commit-complete stop-line
์ปค๋ฐ์ ๋ค์ ์์
์ ๊ณ์ํ๊ธฐ ์ํ ์ค๊ฐ implementation detail์ด ์๋๋ผ ์ฌ์ฉ์-visible save point๋ค.
- commit์ด ๋ง๋ค์ด์ง๋ฉด ๋จผ์ ๋ณด๊ณ ํ๋ค. UI ๊ฒ์ฆ, PR, push, broad status ํ์ธ์ ๋ค์ phase๋ก ๋ถ๋ฆฌํ๋ค.
- ์ฌ์ฉ์๊ฐ ์ด๋ฏธ โ์ปค๋ฐ+ํธ์โ, โPR๊น์งโ, โ๊ฒ์ฆ ๋ฆฌํฌํธ๊น์งโ๋ฅผ ๋ช
์ํ๋ค๋ฉด ์ด์ด๊ฐ ์ ์์ง๋ง, phase๊ฐ ๋ฐ๋์๋ค๋ ์ฌ์ค์ ์งง๊ฒ ํ์ํ๋ค.
- ์ปค๋ฐ ํ
git status, git log, gh pr view ๊ฐ์ ์์ฌ ํ์ธ์ ๊ธฐ๋ณธ ์คํํ์ง ์๋๋ค. ํ์ํ SHA/message๋ commit tool result๋ ์ง์ HEAD์์ ๊ฐ์ ธ์จ๋ค.
- push๊ฐ ํฌํจ๋ light path์์๋ push ์ฑ๊ณต์ด terminal condition์ด๋ค. ์ถ๊ฐ ํ์ธ ๋์ ์งง์ ์๋ฃ ๋ณด๊ณ ๋ฅผ ์ฐ์ ํ๋ค.
- ์ปค๋ฐ์ ๋์ง๋ง UI ๊ฒ์ฆ/ํ๊ฒฝ ๊ฒ์ฆ์ด ๋จ์์ผ๋ฉด โ์ฝ๋ save point ์๋ฃ, ๋จ์ ๊ฒ์ฆ์ ๋ณ๋ phaseโ๋ก ๋ถ๋ฆฌํด caveat๋ฅผ ๋จ๊ธด๋ค.
Pre-Commit Checks
Before every commit:
1. Review what you are committing: git diff --staged
2. Check for secrets: scan for password, secret, api_key, token
3. Run the project's verification:
- test command
- lint / format command
- type check command
If the same validation failure has already been proven unrelated to the current branch, record it as a short-lived known baseline instead of re-debugging it in every worktree. This should happen through automatic preflight handling while the agent works: bash validation failures are checked against the cache, and after root-cause review the agent can call preflight_baseline with action="add_last" to record unrelated baseline noise.
There is no normal user-facing /preflight command. If the user wants to inspect or clean cache state, they can ask in natural language and the agent should use preflight_baseline with list, clear, or prune.
A baseline cache entry only separates noise from actionable failures. It does not make a required check pass and must not hide a failure that changed with the current diff.
Change Summaries
After finishing a set of changes, provide a structured summary:
CHANGES MADE:
- src/routes/signup.ts: added input validation
- src/lib/validation.ts: added email format rule
- tests/routes/signup.test.ts: added validation error test
NOT TOUCHED (intentionally):
- src/routes/login.ts: similar issue but out of scope
CONCERNS:
- New validation may reject previously accepted input. Confirm this is desired.
The "NOT TOUCHED" section shows scope discipline and helps reviewers.
Worktrees for Parallel Work
Pi profiled worktree gate
For repos that a runtime profile marks as protected, do not jump from โthis might need a fixโ to creating a worktree. Before any worktree creation, classify three things:
- Stage โ investigation vs implementation. โํ์ธํด๋ณผ๋?โ means investigate first; do not create a worktree yet.
- Context carry โ if this session already contains investigation, code paths, decisions, or a plan, use
/wt fork / worktree_fork, not /wt new / worktree_create. These fork flows carry the full transcript by default so the new worktree continues the actual source conversation. Use the lightweight handoff only when the user explicitly asks for --minimal-context / minimalContext: true or when copying the transcript would be clearly harmful.
- Base branch โ hotfix/production work must be created with
--hotfix / hotfix: true; do not create a development-based hotfix branch.
Fork-panel rule: child panels (P1, P2, โฆ) must not create protected/profiled worktrees. Hand off findings to the parent panel (/handoff), then the parent (P0) runs /wt fork so the parent conversation becomes the source session. This keeps worktree history, base branch, and session continuity clean.
If a wrong worktree is created, remove it before continuing and create the correct parent-owned fork.
Generic git worktrees
When multiple agents or tasks need separate branches simultaneously outside the managed/profiled flow:
git worktree add ../project-feature-a feature/task-sharing
git worktree add ../project-feature-b feature/user-settings
Each worktree is a separate directory on its own branch. No branch switching needed. Changes are isolated until explicitly merged.
Git for Debugging
git bisect start / bad / good โ binary-search for the commit that introduced a bug
git log --oneline -20 โ see recent history
git diff HEAD~5..HEAD -- path โ see what changed recently in a specific area
git blame path โ find who last changed a line
git log --grep="keyword" โ search commit messages
Handling Generated Files
- Commit lockfiles, checked-in migrations, and generated schemas the project expects
- Do not commit build output, local environment files, or editor config
- Maintain a
.gitignore that covers generated artifacts, secrets, and local-only files
Common Rationalizations
| Rationalization | Reality |
|---|
| "I will commit when the feature is done" | One giant commit is impossible to review or revert safely. Commit each verified slice. |
| "The message does not matter" | Messages are documentation. Future readers need to know what changed and why. |
| "I will squash it later" | Squashing destroys the development narrative. Make clean commits from the start. |
| "Branches add overhead" | Short-lived branches are free. Long-lived ones are the problem โ merge within days. |
| "I will split the change later" | Large changes are harder to review, riskier to deploy, and harder to revert. Split before submitting. |
Red Flags
- Large uncommitted changes accumulating
- Commit messages like "fix", "update", "misc"
- Formatting changes mixed with behavior changes
- No
.gitignore in the project
- Secrets in committed files
- Long-lived branches diverging from main
- Force-pushing to shared branches
Verification
For every commit: