git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git checkout -B <branch> lets you checkout a branch that is already checked out in another worktree Inbox
@ 2023-11-22 19:08 Willem Verstraeten
  2023-11-23  1:28 ` Junio C Hamano
  0 siblings, 1 reply; 17+ messages in thread
From: Willem Verstraeten @ 2023-11-22 19:08 UTC (permalink / raw)
  To: git

# What did you do before the bug happened? (Steps to reproduce your issue)

Clone a repo
Create an additional worktree for that clone
Use `git checkout -B branch-of-primary-clone ...` to checkout the
branch that is already checked out in the primary clone

For example, with the pathfinder repo on GitHub:

    git clone https://github.com/servo/pathfinder.git primary
    cd primary
    git worktree add -b metal ../secondary origin/metal
    cd ../secondary
    git checkout -b main #reports a fatal error, as expected
    git checkout -f main origin/main #also reports a fatal error, as expected
    git checkout -B main origin/main # ----> this succeeds, which is
unexpected <----

# What did you expect to happen? (Expected behavior)

I expected a fatal error stating that the branch could not be checked
out since it was already checked out in my primary worktree

In `git checkout --help`, it is documented that `git checkout -B` is
the atomic equivalent of `git branch -f <branch> <commit> ; git
checkout <branch>` :

> If -B is given, <new-branch> is created if it doesn’t exist; otherwise, it is reset. This is the transactional equivalent of
>
>     $ git branch -f <branch> [<start-point>]
>     $ git checkout <branch>

# What happened instead? (Actual behavior)

The branch was checked out in the secondary worktree. If I then work
and make commits in this secondary worktree, the status of my primary
worktree gets clobbered as well.

What's different between what you expected and what actually happened?

The checkout in the secondary worktree is allowed, but it shouldn't be


[System Info]
git version:
git version 2.41.0
cpu: arm64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
uname: Darwin 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:21:53
PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6020 arm64
compiler info: clang: 14.0.3 (clang-1403.0.22.14.1)
libc info: no libc information available
$SHELL (typically, interactive shell): /bin/zsh


[Enabled Hooks]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-01-30 22:30 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-22 19:08 git checkout -B <branch> lets you checkout a branch that is already checked out in another worktree Inbox Willem Verstraeten
2023-11-23  1:28 ` Junio C Hamano
2023-11-23  5:58   ` Junio C Hamano
2023-11-23  6:00     ` [PATCH 2/2] checkout: forbid "-B <branch>" from touching a branch used elsewhere Junio C Hamano
2023-11-23 16:33       ` Phillip Wood
2023-11-23 17:09         ` Eric Sunshine
2023-11-24  1:19           ` Junio C Hamano
2023-11-27  1:51         ` Junio C Hamano
2023-11-27 21:31           ` Jeff King
2023-11-30 15:22           ` Phillip Wood
2023-12-04 12:20             ` Willem Verstraeten
2023-12-04 21:06               ` Eric Sunshine
2023-12-08 17:13                 ` Junio C Hamano
2024-01-30 12:37                   ` Willem Verstraeten
2024-01-30 22:30                     ` Junio C Hamano
2023-11-23 22:03     ` git checkout -B <branch> lets you checkout a branch that is already checked out in another worktree Inbox Andy Koppe
2023-11-23 12:12   ` Willem Verstraeten

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).