Skip to content

Commit fc37b80

Browse files
MrFlounderclaude
andcommitted
fix: force checkout in restart/cleanup to handle dirty worktrees
When a workspace is on a different branch with uncommitted changes, `git checkout` fails silently and the `-b` fallback fails because the branch already exists. Since restart and cleanup are explicitly destructive (reset --hard follows immediately), use `-f` to force past dirty trees and `-B` to handle existing branches. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 51bca5b commit fc37b80

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/crabcode

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ cleanup_workspace() {
17251725
git fetch origin
17261726

17271727
echo " Resetting to origin/main..."
1728-
git checkout main 2>/dev/null || git checkout -b main origin/main
1728+
git checkout -f main 2>/dev/null || git checkout -f -B main origin/main
17291729
git reset --hard origin/main
17301730

17311731
echo " Cleaning untracked files..."
@@ -1833,7 +1833,7 @@ restart_workspace() {
18331833

18341834
if [ "$current_branch" != "$branch_name" ]; then
18351835
echo " Switching from $current_branch to $branch_name..."
1836-
git checkout "$branch_name" 2>/dev/null || git checkout -b "$branch_name"
1836+
git checkout -f "$branch_name" 2>/dev/null || git checkout -f -B "$branch_name"
18371837
fi
18381838

18391839
echo " Resetting $branch_name to origin/main content..."

0 commit comments

Comments
 (0)