path: root/t
diff options
authorEric Sunshine <>2020-02-23 10:14:07 (GMT)
committerJunio C Hamano <>2020-02-24 19:34:41 (GMT)
commitb5cabb4a967fa455378ee7ddfa831a9bf0244753 (patch)
treeff679012db6fa875e43265ced26a6e1548872b1c /t
parentdf126ca14269efaf4d28453743a386be81ebec85 (diff)
rebase: refuse to switch to branch already checked out elsewhere
The invocation "git rebase <upstream> <branch>" switches to <branch> before performing the rebase operation. However, unlike git-switch, git-checkout, and git-worktree which all refuse to switch to a branch that is already checked out in some other worktree, git-rebase switches to <branch> unconditionally. Curb this careless behavior by making git-rebase also refuse to switch to a branch checked out elsewhere. Reported-by: Mike Hommey <> Signed-off-by: Eric Sunshine <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 't')
1 files changed, 18 insertions, 0 deletions
diff --git a/t/ b/t/
index 6e746dc..9aa5268 100755
--- a/t/
+++ b/t/
@@ -377,4 +377,22 @@ test_expect_success 'rebase -c rebase.useBuiltin=false warning' '
test_must_be_empty err
+test_expect_success 'switch to branch checked out here' '
+ git checkout master &&
+ git rebase master master
+test_expect_success 'switch to branch not checked out' '
+ git checkout master &&
+ git branch other &&
+ git rebase master other
+test_expect_success 'refuse to switch to branch checked out elsewhere' '
+ git checkout master &&
+ git worktree add wt &&
+ test_must_fail git -C wt rebase master master 2>err &&
+ test_i18ngrep "already checked out" err