---
name: git-workflow
description: Automate the complete Git development workflow — create feature branches with conventional naming, atomic commits with conventional commit messages, interactive rebase, squash merges, PR body generation from commit history, branch cleanup, and git worktree patterns. Use when user asks to create a branch, commit changes, make a PR, rebase, squash, clean up branches, or follow a Git workflow. Do NOT use for CI/CD pipeline configuration (use ci-cd), code review (use code-review), or GitHub Actions workflows.
triggers:
- "git branch"
- "create branch"
- "commit"
- "git commit"
- "git push"
- "git rebase"
- "squash commits"
- "git workflow"
- "make a PR"
- "pull request"
- "git merge"
- "git cleanup"
- "branch management"
- "conventional commit"
negatives:
- "CI/CD pipeline"
- "GitHub Actions"
- "code review"
- "GitHub workflow"
- "GitLab CI"
license: MIT
compatibility: opencode
metadata:
workflow: development
audience: developers
version: "3.0.0"
author: shokunin
allowed-tools: Read Bash Write Grep
Git Workflow
Automate the development cycle: branch, commit, PR, review, merge, cleanup. Follows conventional commits and trunk-based development.
Workflow
Step 1: Create a feature branch
scripts/create-feature-branch.ps1 -Name "add-user-auth" -Type feat
This:
- Detects default branch (main/master)
- Fetches and pulls latest
- Creates
feat/add-user-auth from base
- Pushes upstream with tracking
Branch naming:
| Type |
Prefix |
Example |
| Feature |
feat/ |
feat/add-user-auth |
| Fix |
fix/ |
fix/login-redirect |
| Docs |
docs/ |
docs/api-readme |
| Refactor |
refactor/ |
refactor/auth-middleware |
| Chore |
chore/ |
chore/update-deps |
Step 2: Make atomic commits
scripts/auto-commit.ps1 -Scope "auth" -DryRun # Preview first
scripts/auto-commit.ps1 -Scope "auth" # Commit
The script analyses changed files, generates a conventional commit message, and stages+commits.
Conventional commit format:
<type>(<scope>): <description>
[optional body]
[optional footer]
Rules:
- One logical change per commit
- Description: imperative mood, lowercase, max 72 chars
- Scope: the module/area affected
- Footer:
BREAKING CHANGE:, Closes #123, Co-authored-by:
Step 3: Prepare for PR
# Interactive rebase (squash WIP commits)
git rebase -i main
# Generate PR body from commit history
scripts/pr-body.ps1 -Clipboard
The PR body script:
- Detects base branch
- Extracts commits since fork
- Groups by conventional commit type
- Generates ## Summary, ## Changes, ## Testing sections
- Copies to clipboard
Squash rules:
- Squash
fixup! and wip commits
- Keep meaningful commit history
- Never squash if commits have different scopes
- Use
git rebase -i main with fixup (f) for WIP commits
Step 4: Create PR
# Create PR with generated body
gh pr create --title "feat(auth): add user authentication" --body "$(Get-Clipboard)"
# Or use the file
gh pr create --title "feat(auth): add user authentication" --body-file .pr-body.md
PR guidelines:
| Aspect |
Rule |
| Size |
Max 400 lines changed |
| Title |
Same as conventional commit |
| Description |
What + Why + How to test |
| Reviewers |
1-2 relevant team members |
| Labels |
Type (feat/fix/docs) + priority |
| Draft |
Use for Work-in-Progress |
Step 5: Clean up after merge
scripts/cleanup-branches.ps1
This lists merged branches (excluding protected ones), asks for confirmation, deletes locally and remotely, and prunes remote tracking refs.
Workflow by strategy
See references/git-workflows.md for full reference.
| Strategy |
Best for |
Branch model |
Pros |
Cons |
Guidance |
| Trunk-based |
CI/CD, deploys multiple times/day, feature flags |
Short-lived feature branches → main (hours, not days) |
Fast integration, no merge hell, simple CI |
Requires feature flags + high test coverage |
Keep branches under 24h. Use branch by abstraction for large changes. |
| GitHub Flow |
Standard SaaS, team of 2-10 |
feature → main (PR + squash merge) |
Simple, review-friendly, clean history |
Can't manage multiple releases |
Use for most projects. Squash-merge keeps main linear. Tag releases from main. |
| GitFlow |
Release management, multiple supported versions, regulated industries |
feature → develop → release → main + hotfix branches |
Full version tracking, parallel releases |
High complexity, slow to release |
Only use if you support 2+ release versions simultaneously. Overkill for single-version SaaS. |
| GitLab Flow |
Environment-based deployments, staging → production gating |
feature → main → staging → production (branch per env) |
Environment isolation, easy rollback |
Duplicate merge overhead per env |
Use when environments need different merge cadences. Pair with CI/CD environment protection. |
Default recommendation: GitHub Flow for simplicity. Trunk-based if CI/CD is mature and deploying multiple times/day.
Error Handling
| Scenario |
Cause |
Fix |
| Rebase conflicts |
Multiple people changed same lines |
Resolve conflicts, git rebase --continue. See conflict resolution workflow below. |
| Can't push (non-fast-forward) |
Branch behind base |
Rebase on base first |
| Accidental commit on wrong branch |
Careless checkout |
Cherry-pick to correct branch, reset original |
| Detached HEAD |
Accidentally checked out a commit |
git switch -c <new-branch> |
| Lost commits after reset |
git reset --hard |
git reflog → find SHA → git cherry-pick |
Rebase conflict resolution
# During rebase, conflict arises
git status # See conflicted files
# Edit conflicted files → resolve markers (<<<<<<, ======, >>>>>>)
git add <resolved-files>
git rebase --continue # Move to next commit
# If the rebase is going poorly and you want to bail:
git rebase --abort # Return to pre-rebase state
# If you're mid-rebase, unsure, and want to compare:
git diff # Show conflict diff
git mergetool # Launch configured merge tool (VS Code: code --wait $MERGED)
# Skip a problematic commit entirely:
git rebase --skip
# After rebase, verify history:
git log --oneline --graph -20
Conflict avoidance:
- Keep branches short-lived (< 3 days). Longer branches accumulate merge debt.
- Pull/rebase daily from main during long features:
git fetch origin && git rebase origin/main
- Break large features into stacked PRs (PR 1 → PR 2 → PR 3) instead of one 1000-line PR
- Communicate: if you're refactoring a shared module, tell the team
Parallel work with git worktree
Use git worktree to work on multiple branches simultaneously without stashing or cloning:
# Create a new worktree for a feature
git worktree add ../project-feat-auth feat/add-user-auth
# List all worktrees
git worktree list
# Remove a worktree after branch is merged
git worktree remove ../project-feat-auth
# Then delete the branch normally
When to use:
- Hotfix needs to go out while you're mid-feature on another branch
- Running CI/lint/tests in one worktree while coding in another
- Reviewing a PR branch without switching away from your current work
- Exploring an old commit without detaching HEAD
Branch Protection Rules
| Rule |
GitHub setting |
Why |
| Require PR before merge |
required_pull_request_reviews |
Prevents direct pushes |
| Require status checks |
required_status_checks |
CI must pass |
| Require linear history |
required_linear_history |
No merge commits |
| Require signed commits |
required_signatures |
Verify authorship |
| Dismiss stale reviews |
dismiss_stale_reviews |
New pushes need re-review |
Production Checklist
Anti-Patterns
| Anti-pattern |
Fix |
git commit -m "fix bug" |
Conventional commit with context |
| 1000+ line PRs |
Break into smaller, atomic changes |
| Merging main into feature branch |
Rebase instead (cleaner history) |
| Committing directly to main |
Branch + PR + review always |
| No CI before merge |
Block merging without passing checks |
| Pushing to main without PR |
Use branch protection rules |
| Stale branches (older than 2 weeks) |
Clean up regularly |
Sources
- Conventional Commits (conventionalcommits.org)
- GitHub Flow (docs.github.com)
- Trunk-Based Development (trunkbaseddevelopment.com)
- Git SCM docs (git-scm.com)
- Keep a Changelog (keepachangelog.com)
- Semantic Versioning (semver.org)
Checklist
1---2name: git-workflow3description: ---4---5---6name: git-workflow7description: Automate the complete Git development workflow — create feature branches with conventional naming, atomic commits with conventional commit messages, interactive rebase, squash merges, PR body generation from commit history, branch cleanup, and git worktree patterns. Use when user asks to create a branch, commit changes, make a PR, rebase, squash, clean up branches, or follow a Git workflow. Do NOT use for CI/CD pipeline configuration (use ci-cd), code review (use code-review), or GitHub Actions workflows.8triggers:9 - "git branch"10 - "create branch"11 - "commit"12 - "git commit"13 - "git push"14 - "git rebase"15 - "squash commits"16 - "git workflow"17 - "make a PR"18 - "pull request"19 - "git merge"20 - "git cleanup"21 - "branch management"22 - "conventional commit"23negatives:24 - "CI/CD pipeline"25 - "GitHub Actions"26 - "code review"27 - "GitHub workflow"28 - "GitLab CI"29license: MIT30compatibility: opencode31metadata:32 workflow: development33 audience: developers34 version: "3.0.0"35 author: shokunin36allowed-tools: Read Bash Write Grep37---383940# Git Workflow4142Automate the development cycle: branch, commit, PR, review, merge, cleanup. Follows conventional commits and trunk-based development.4344## Workflow4546### Step 1: Create a feature branch4748```powershell49scripts/create-feature-branch.ps1 -Name "add-user-auth" -Type feat50```5152This:531. Detects default branch (main/master)542. Fetches and pulls latest553. Creates `feat/add-user-auth` from base564. Pushes upstream with tracking5758**Branch naming:**59| Type | Prefix | Example |60|------|--------|---------|61| Feature | `feat/` | `feat/add-user-auth` |62| Fix | `fix/` | `fix/login-redirect` |63| Docs | `docs/` | `docs/api-readme` |64| Refactor | `refactor/` | `refactor/auth-middleware` |65| Chore | `chore/` | `chore/update-deps` |6667### Step 2: Make atomic commits6869```powershell70scripts/auto-commit.ps1 -Scope "auth" -DryRun # Preview first71scripts/auto-commit.ps1 -Scope "auth" # Commit72```7374The script analyses changed files, generates a conventional commit message, and stages+commits.7576**Conventional commit format:**77```78<type>(<scope>): <description>7980[optional body]8182[optional footer]83```8485**Rules:**86- One logical change per commit87- Description: imperative mood, lowercase, max 72 chars88- Scope: the module/area affected89- Footer: `BREAKING CHANGE:`, `Closes #123`, `Co-authored-by:`9091### Step 3: Prepare for PR9293```powershell94# Interactive rebase (squash WIP commits)95git rebase -i main9697# Generate PR body from commit history98scripts/pr-body.ps1 -Clipboard99```100101The PR body script:1021. Detects base branch1032. Extracts commits since fork1043. Groups by conventional commit type1054. Generates ## Summary, ## Changes, ## Testing sections1065. Copies to clipboard107108**Squash rules:**109- Squash `fixup!` and `wip` commits110- Keep meaningful commit history111- Never squash if commits have different scopes112- Use `git rebase -i main` with `fixup` (f) for WIP commits113114### Step 4: Create PR115116```powershell117# Create PR with generated body118gh pr create --title "feat(auth): add user authentication" --body "$(Get-Clipboard)"119120# Or use the file121gh pr create --title "feat(auth): add user authentication" --body-file .pr-body.md122```123124**PR guidelines:**125| Aspect | Rule |126|--------|------|127| Size | Max 400 lines changed |128| Title | Same as conventional commit |129| Description | What + Why + How to test |130| Reviewers | 1-2 relevant team members |131| Labels | Type (feat/fix/docs) + priority |132| Draft | Use for Work-in-Progress |133134### Step 5: Clean up after merge135136```powershell137scripts/cleanup-branches.ps1138```139140This lists merged branches (excluding protected ones), asks for confirmation, deletes locally and remotely, and prunes remote tracking refs.141142## Workflow by strategy143144See [references/git-workflows.md](references/git-workflows.md) for full reference.145146| Strategy | Best for | Branch model | Pros | Cons | Guidance |147|----------|----------|--------------|------|------|----------|148| **Trunk-based** | CI/CD, deploys multiple times/day, feature flags | Short-lived feature branches → main (hours, not days) | Fast integration, no merge hell, simple CI | Requires feature flags + high test coverage | Keep branches under 24h. Use branch by abstraction for large changes. |149| **GitHub Flow** | Standard SaaS, team of 2-10 | feature → main (PR + squash merge) | Simple, review-friendly, clean history | Can't manage multiple releases | Use for most projects. Squash-merge keeps main linear. Tag releases from main. |150| **GitFlow** | Release management, multiple supported versions, regulated industries | feature → develop → release → main + hotfix branches | Full version tracking, parallel releases | High complexity, slow to release | Only use if you support 2+ release versions simultaneously. Overkill for single-version SaaS. |151| **GitLab Flow** | Environment-based deployments, staging → production gating | feature → main → staging → production (branch per env) | Environment isolation, easy rollback | Duplicate merge overhead per env | Use when environments need different merge cadences. Pair with CI/CD environment protection. |152153**Default recommendation**: GitHub Flow for simplicity. Trunk-based if CI/CD is mature and deploying multiple times/day.154155## Error Handling156157| Scenario | Cause | Fix |158|----------|-------|-----|159| Rebase conflicts | Multiple people changed same lines | Resolve conflicts, `git rebase --continue`. See conflict resolution workflow below. |160| Can't push (non-fast-forward) | Branch behind base | Rebase on base first |161| Accidental commit on wrong branch | Careless checkout | Cherry-pick to correct branch, reset original |162| Detached HEAD | Accidentally checked out a commit | `git switch -c <new-branch>` |163| Lost commits after reset | `git reset --hard` | `git reflog` → find SHA → `git cherry-pick` |164165## Rebase conflict resolution166167```168# During rebase, conflict arises169git status # See conflicted files170# Edit conflicted files → resolve markers (<<<<<<, ======, >>>>>>)171git add <resolved-files>172git rebase --continue # Move to next commit173174# If the rebase is going poorly and you want to bail:175git rebase --abort # Return to pre-rebase state176177# If you're mid-rebase, unsure, and want to compare:178git diff # Show conflict diff179git mergetool # Launch configured merge tool (VS Code: code --wait $MERGED)180181# Skip a problematic commit entirely:182git rebase --skip183184# After rebase, verify history:185git log --oneline --graph -20186```187188**Conflict avoidance:**189- Keep branches short-lived (< 3 days). Longer branches accumulate merge debt.190- Pull/rebase daily from main during long features: `git fetch origin && git rebase origin/main`191- Break large features into stacked PRs (PR 1 → PR 2 → PR 3) instead of one 1000-line PR192- Communicate: if you're refactoring a shared module, tell the team193194## Parallel work with git worktree195196Use `git worktree` to work on multiple branches simultaneously without stashing or cloning:197198```powershell199# Create a new worktree for a feature200git worktree add ../project-feat-auth feat/add-user-auth201202# List all worktrees203git worktree list204205# Remove a worktree after branch is merged206git worktree remove ../project-feat-auth207# Then delete the branch normally208```209210**When to use:**211- Hotfix needs to go out while you're mid-feature on another branch212- Running CI/lint/tests in one worktree while coding in another213- Reviewing a PR branch without switching away from your current work214- Exploring an old commit without detaching HEAD215216## Branch Protection Rules217218| Rule | GitHub setting | Why |219|------|---------------|-----|220| Require PR before merge | `required_pull_request_reviews` | Prevents direct pushes |221| Require status checks | `required_status_checks` | CI must pass |222| Require linear history | `required_linear_history` | No merge commits |223| Require signed commits | `required_signatures` | Verify authorship |224| Dismiss stale reviews | `dismiss_stale_reviews` | New pushes need re-review |225226## Production Checklist227228- [ ] Branch named with conventional prefix229- [ ] Commit message follows conventional commits230- [ ] One logical change per commit231- [ ] PR description explains what + why + how to test232- [ ] PR under 400 lines changed233- [ ] CI passes (lint, typecheck, tests)234- [ ] At least 1 reviewer approved235- [ ] Branch deleted after merge236- [ ] No WIP commits in history237238## Anti-Patterns239240| Anti-pattern | Fix |241|-------------|-----|242| `git commit -m "fix bug"` | Conventional commit with context |243| 1000+ line PRs | Break into smaller, atomic changes |244| Merging main into feature branch | Rebase instead (cleaner history) |245| Committing directly to main | Branch + PR + review always |246| No CI before merge | Block merging without passing checks |247| Pushing to main without PR | Use branch protection rules |248| Stale branches (older than 2 weeks) | Clean up regularly |249250## Sources251252- Conventional Commits (conventionalcommits.org)253- GitHub Flow (docs.github.com)254- Trunk-Based Development (trunkbaseddevelopment.com)255- Git SCM docs (git-scm.com)256- Keep a Changelog (keepachangelog.com)257- Semantic Versioning (semver.org)258259## Checklist260261- [ ] Skill loads without errors in the AI agent262- [ ] YAML frontmatter is valid (description, compatibility, audience)263- [ ] Workflow section provides clear step-by-step instructions264- [ ] Error handling section covers common failure modes265- [ ] All referenced files (references/, scripts/, assets/) exist266- [ ] Skill triggers correctly for intended use cases267- [ ] No broken links or missing resources