git-worktree-enforcement
Mandatory git worktree policy ensuring feature work happens in worktrees/ subdirectories, not the main clone
Git Worktree Enforcement Skill
You enforce a mandatory git worktree policy: all feature work must happen inside worktrees/ subdirectories, never in the main clone.
Policy Rules
1. Main Clone on main Only
The base clone must stay on main (or master) at all times. Never checkout a feature branch in the main clone.
2. Feature Work in worktrees/ Only
All branches with these prefixes must be checked out as worktrees inside worktrees/:
feature/*,fix/*,refactor/*,hotfix/*,bugfix/*,chore/*,docs/*,release/*
3. Branch-to-Folder Naming
Slashes become hyphens:
feature/user-auth→worktrees/feature-user-authfix/login-bug→worktrees/fix-login-bughotfix/critical-patch→worktrees/hotfix-critical-patch
4. Gitignore
worktrees/ must be listed in .gitignore.
Pre-Flight Check (Before Any Git Write Operation)
- Run
pwd- confirm you are insideworktrees/<name> - Run
git branch --show-current- confirm you are on the expected feature branch - If on a feature branch but NOT inside
worktrees/→ STOP and relocate
Standard Workflow
Create a New Feature Branch
cd /path/to/repo
git branch --show-current # must be: main
grep -q '^worktrees/' .gitignore || echo 'worktrees/' >> .gitignore
git worktree add worktrees/feature-my-feature -b feature/my-feature main
cd worktrees/feature-my-feature
# ALL work happens here
Work on an Existing Branch
git fetch origin
git worktree add worktrees/feature-existing feature/existing
cd worktrees/feature-existing
Cleanup After Merge
cd /path/to/repo # main clone
git worktree remove worktrees/feature-my-feature
git worktree prune
What This Prevents
- Branch conflicts between concurrent sessions
- Lost work from accidental branch switches
- Clobbered changes from multiple tools on the same checkout
- Detached HEAD from working in wrong directory
When to Apply This Skill
- Before ANY git write operation (commit, add, push, merge, rebase)
- When creating new feature branches
- When switching between tasks or features
- When onboarding to a new repository
Related Assets
git-expert
Git version control, branching strategies, advanced operations, troubleshooting, and collaboration workflows
Owner: platform-devops
AWX Configuration as Code (CaC) Style and Safety
Standard patterns and safety rules for AWX operations using the ansible_role_awx_cac Configuration as Code model in Epic on Azure at Optum.
Owner: epic-platform-sre
Kubernetes Operations Style and Safety
Conventions and guardrails for Kubernetes operations in Optum clusters, emphasizing read-only diagnostics and GitOps-driven changes.
Owner: epic-platform-sre
Prune Git Worktrees
Safely prune git worktrees whose branches have been merged into the remote default. Uses authoritative gh API merged-PR detection plus remote-branch and ancestry checks. Skips worktrees with uncommitted or unpushed work.
Owner: epic-platform-sre
Terraform Conventions
Terraform conventions and guardrails for safe, maintainable Infrastructure as Code.
Owner: epic-platform-sre
Terraform Style and Safety for TFE-Backed Workspaces
Terraform coding conventions, safety rules, and best practices for Terraform Enterprise (TFE) backed workspaces in Optum environments.
Owner: epic-platform-sre

