Skip to content

Add wt.branchprefix config to decouple branch names from worktree directory names#171

Closed
glasser wants to merge 1 commit into
k1LoW:mainfrom
glasser:glasser/branchprefix
Closed

Add wt.branchprefix config to decouple branch names from worktree directory names#171
glasser wants to merge 1 commit into
k1LoW:mainfrom
glasser:glasser/branchprefix

Conversation

@glasser

@glasser glasser commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds wt.branchprefix config option (and --branchprefix flag) that prepends a prefix to branch names when creating new branches, while keeping the worktree directory name short
  • Example: with git config wt.branchprefix "username/", git wt foo creates branch username/foo in directory .wt/foo
  • Existing branches matching the exact input are used as-is (no prefix added), so git wt main still works naturally
  • Input already starting with the prefix is not doubled

Test plan

  • E2E tests added covering: config, flag override, switch by dir name, switch by prefixed branch name, existing branch not getting prefixed, already-prefixed input not doubled, and start-point support
  • Verify all existing tests still pass (go test ./...)

🤖 Generated with Claude Code

…ectory names

When wt.branchprefix is set (e.g., "username/"), new branches are created
with the prefix prepended (e.g., "username/my-feature") while the worktree
directory uses the short name (e.g., ".wt/my-feature").

Key behaviors:
- Existing branches matching the exact input are used as-is (no prefix added)
- Input already starting with the prefix is not doubled
- Worktrees can be found by either the short dir name or the full branch name
- Supports both git config and --branchprefix flag override

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@k1LoW

k1LoW commented Apr 8, 2026

Copy link
Copy Markdown
Owner

Thank you for the well-crafted PR with thorough tests and documentation!

After consideration, I've decided not to merge this feature for the following reasons.

  1. Limited use case for a single static prefix
    • In practice, branch naming conventions vary (e.g., username/, feat/, fix/), and a single fixed prefix covers only a narrow set of workflows
    • Supporting more flexible patterns would add significant complexity
  2. Marginal benefit of shorter directory names
    • With git wt's shell integration (git wt auto-cd), users rarely need to type or navigate worktree directory paths directly
    • The convenience gain from shorter directory names is not substantial enough to justify the added configuration surface and the extra lookup logic throughout the codebase

I appreciate the contribution and the time you put into this. Feel free to open an issue if you'd like to discuss alternative approaches.

@glasser

glasser commented Apr 8, 2026

Copy link
Copy Markdown
Contributor Author

That's fair. I think a simpler approach would just be to allow git wt in branch-creation mode take the branch and directory name as separate arguments? Then I can wrap it if I'd like with something that matches my personal standard.

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.

2 participants