Git workflow: branches + worktrees
Non-negotiables
- •All work happens on a branch. Never commit on
master/main. - •Branch names must follow the conventions below.
- •Prefer using a git worktree per task so context stays clean and you don’t trample other work.
Branch naming (Conventional Commit aligned)
Without ticket
- •
feat/<short-kebab> - •
fix/<short-kebab> - •
refactor/<short-kebab> - •
chore/<short-kebab> - •
docs/<short-kebab>
With ticket
- •
feat/TICKET-123 - •
fix/TICKET-123 - •
refactor/TICKET-123
Optional (still keep it short):
- •
feat/TICKET-123-short-kebab - •
fix/TICKET-123-short-kebab - •
refactor/TICKET-123-short-kebab
Rules:
- •Keep it minimal: no essays.
- •Use lowercase + hyphens.
Worktree workflow
Detect whether we’re in a worktree
- •Use
git rev-parse --is-inside-work-treeandgit rev-parse --is-bare-repository.
If we are asked to "pick up work" or start a new task
If we’re already in a git worktree, create a new dedicated worktree for the new task.
Preferred entrypoint:
- •Use the
/worktree:newcommand (it creates the worktree in the correct place and handles existing branches).
Steps:
- •Find the worktree root repo:
- •Run
git rev-parse --git-common-dir. - •If it ends with
/worktrees/<name>, you are inside a linked worktree. - •The top-level directory is the parent of that common dir.
- •Create a new worktree directory in the top-level repo Use:
code
# from the top-level repo directory git worktree add <TICKET_OR_MIN_DESC> -b <branch-name>
- •
<TICKET_OR_MIN_DESC>: directory name, minimal (e.g.VET-123orfix-nix-eval) - •
<branch-name>: must follow the branch naming rules above
If the branch already exists:
code
git worktree add <TICKET_OR_MIN_DESC> <branch-name>
Safety checks before doing anything
- •If on
master/main: stop and create a branch (or worktree) first. - •If the branch name doesn’t follow conventions: rename it before continuing.