Skip to content

Git Worktree Enforcement

Mandatory git worktree policy preventing branch conflicts and lost work by requiring all feature work in worktrees/ subdirectories.

active
IDE:
claude
codex
vscode
Version:
1.0.0
Owner:platform-devops
git
worktree
branching
enforcement
version-control
safety

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:

  1. pwd - Am I inside worktrees/<name>?
  2. git branch --show-current - Am I on the expected branch?
  3. 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