Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Improve hint when --create shadows a remote branch (#588)

Maximilian Roos800998130e15
diff --git a/.claude/rules/cli-output-formatting.md b/.claude/rules/cli-output-formatting.md
index da33eeca7..331ddbfd3 100644
--- a/.claude/rules/cli-output-formatting.md
+++ b/.claude/rules/cli-output-formatting.md
@@ -317,8 +317,8 @@ command for easy copying:
"To delete the unmerged branch, run wt remove feature -D"
"To rebase onto main, run wt step rebase or wt merge"
-// GOOD - when user needs to modify their command
-"To switch to the remote branch, remove --create; run wt switch feature"
+// GOOD - recovery command after shadowing a remote branch
+"To switch to the remote branch, remove this added branch and then run without --create: wt remove feature && wt switch feature"
// BAD - command without context
"wt remove feature -D deletes unmerged branches"
diff --git a/src/commands/worktree.rs b/src/commands/worktree.rs
index ac7920ab1..4c6b80834 100644
--- a/src/commands/worktree.rs
+++ b/src/commands/worktree.rs
@@ -459,9 +459,10 @@ pub fn handle_switch(
crate::output::print(warning_message(cformat!(
"Branch <bold>{resolved_branch}</> exists on remote ({remote_ref}); creating new branch from base instead"
)))?;
- let cmd = suggest_command("switch", &[&resolved_branch], &[]);
+ let remove_cmd = suggest_command("remove", &[&resolved_branch], &[]);
+ let switch_cmd = suggest_command("switch", &[&resolved_branch], &[]);
crate::output::print(hint_message(cformat!(
- "To switch to the remote branch, remove <bright-black>--create</>; run <bright-black>{cmd}</>"
+ "To switch to the remote branch, remove this added branch and then run without <bright-black>--create</>: <bright-black>{remove_cmd} && {switch_cmd}</>"
)))?;
}
}
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_create_remote_only.snap b/tests/snapshots/integration__integration_tests__switch__switch_create_remote_only.snap
index d7d01a256..c4013753f 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_create_remote_only.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_create_remote_only.snap
@@ -9,7 +9,7 @@ info:
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
- COLUMNS: "150"
+ COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
@@ -34,7 +34,7 @@ exit_code: 0
----- stderr -----
▲ Branch remote-feature exists on remote (origin/remote-feature); creating new branch from base instead
-↳ To switch to the remote branch, remove --create; run wt switch remote-feature
+↳ To switch to the remote branch, remove this added branch and then run without --create: wt remove remote-feature && wt switch remote-feature
✓ Created branch remote-feature and worktree from main @ _REPO_.remote-feature
↳ Customize worktree locations: wt config create
▲ Cannot change directory — shell integration not installed