From: Jinwook Jeong <vustthat@gmail.com>
To: git@vger.kernel.org
Subject: bugreport: "git checkout -B" allows checking out one branch across multiple worktrees
Date: Sat, 14 Jan 2023 18:45:34 +0900 [thread overview]
Message-ID: <CAA3Q-aaO=vcZd9VLFr8UP-g06be80eUWN_GjygfyGkYmrLx9yQ@mail.gmail.com> (raw)
What did you do before the bug happened? (Steps to reproduce your issue)
1. `cd` into any git repo that has at least one commit.
2. Identify the current branch, say main
3. $ git branch foo # a new branch
4. $ git worktree add ../new_worktree foo
5. $ cd ../new_worktree
6. $ git checkout -B master HEAD
What did you expect to happen? (Expected behavior)
git prints out "Fatal: 'main' is already checked out at ..." (or
similar message that informs me that I'm not allowed to doubly
checkout one branch)
What happened instead? (Actual behavior)
The new_worktree successfully changes its current branch to master,
which is already held by another worktree.
Anything else you want to add:
https://www.git-scm.com/docs/git-checkout#Documentation/git-checkout.txt-emgitcheckoutem-b-Bltnew-branchgtltstart-pointgt
According to the documentation, "git checkout -B BRANCH START" is the
transactionally equivalent of:
git branch -f BRANCH START
git checkout BRANCH
When I ran the first command in place of the step 6 of the above
reproducing procedure, git refused to carry on;
I suppose that this is the intended behavior for "git checkout -B".
[System Info]
git version:
git version 2.39.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 21.6.0 Darwin Kernel Version 21.6.0: Sun Nov 6 23:31:13
PST 2022; root:xnu-8020.240.14~1/RELEASE_ARM64_T6000 arm64
compiler info: clang: 14.0.0 (clang-1400.0.29.202)
libc info: no libc information available
$SHELL (typically, interactive shell): /opt/homebrew/bin/bash
[Enabled Hooks]
not run from a git repository - no hooks to show
next reply other threads:[~2023-01-14 9:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-14 9:45 Jinwook Jeong [this message]
2023-01-16 0:11 ` bugreport: "git checkout -B" allows checking out one branch across multiple worktrees Carlo Marcelo Arenas Belón
2023-01-16 1:07 ` Eric Sunshine
2023-01-16 2:50 ` Jinwook Jeong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAA3Q-aaO=vcZd9VLFr8UP-g06be80eUWN_GjygfyGkYmrLx9yQ@mail.gmail.com' \
--to=vustthat@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).