Git Worktree Enforcement
Mandatory git worktree policy preventing branch conflicts and lost work by requiring all feature work in worktrees/ subdirectories.
Git Worktree Enforcement
MANDATORY: Never Work in the Main Clone
When assisting with git operations in any repository, you MUST follow these rules:
Rule 1: Main Clone on main Only
The base clone of the repository must stay on the main (or master) branch at all times. Never checkout a feature branch in the main clone.
Rule 2: Feature Work in worktrees/ Only
All feature, fix, hotfix, bugfix, refactor, chore, docs, and release branches must be checked out as worktrees inside the worktrees/ subdirectory.
Rule 3: Branch-to-Folder Naming
Slashes become hyphens: feature/user-auth becomes worktrees/feature-user-auth.
Rule 4: Gitignore
worktrees/ must be in .gitignore.
Before Any Git Write Operation
Run this pre-flight check:
pwd- Am I insideworktrees/<name>?git branch --show-current- Am I on the expected branch?- If on a feature branch but NOT inside
worktrees/- STOP
Creating a Worktree
# From repo root (on main)
git worktree add worktrees/feature-my-feature -b feature/my-feature main
cd worktrees/feature-my-feature
Cleaning Up
cd /path/to/repo # back to main clone
git worktree remove worktrees/feature-my-feature
git worktree prune
Why This Matters
- Prevents branch conflicts between concurrent sessions
- Prevents lost work from accidental branch switches
- Prevents clobbered changes from multiple tools operating on same checkout
- Each worktree is fully isolated with its own working directory
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

