Skip to content

Add main_branch config key for branch protection and base branch selection#10

Merged
bkildow merged 1 commit intomainfrom
feature/main-branch-config
Mar 24, 2026
Merged

Add main_branch config key for branch protection and base branch selection#10
bkildow merged 1 commit intomainfrom
feature/main-branch-config

Conversation

@bkildow
Copy link
Copy Markdown
Owner

@bkildow bkildow commented Mar 24, 2026

Summary

  • Adds main_branch field to .worktree.yml config (defaults to main, auto-detected at clone/init time)
  • wt remove now refuses to delete the main branch worktree (hard guard, no --force override)
  • wt add creates new branches from the configured main branch instead of implicit HEAD
  • wt prune uses the config value instead of runtime GetDefaultBranch() detection
  • Adds ResolveStartPoint() helper that tries origin/<branch>, local <branch>, then HEAD for robust ref resolution in bare repos
  • Updates README and AGENTS.md documentation with the new config key

Test plan

  • make dev passes (fmt, vet, all tests including e2e)
  • wt clone <repo> writes main_branch: <detected> to .worktree.yml
  • wt init in an existing repo detects and writes the default branch
  • wt add feature/test creates a new branch from the configured main branch
  • wt remove main is rejected with an error message
  • wt prune still protects the main branch from removal
  • Existing projects without main_branch in config default to main (backward compat)

…ction

Introduces a main_branch field in .worktree.yml that serves as the single
source of truth for the repository's primary branch. This solves three
problems: wt remove now refuses to delete the main branch worktree,
wt add creates new branches from the configured main branch instead of
HEAD, and wt prune uses the config value instead of runtime detection.

The main branch is auto-detected at clone/init time and written to config.
Existing projects without main_branch default to "main" for backward
compatibility.
@bkildow bkildow merged commit 3582d06 into main Mar 24, 2026
@bkildow bkildow deleted the feature/main-branch-config branch March 24, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant