git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Kevin Daudt <me@ikke.info>
Cc: "Randall S. Becker" <rsbecker@nexbridge.com>,
	'COLLOMB Joris -EXT' <joris.collomb-ext@alstomgroup.com>,
	git@vger.kernel.org
Subject: Re: Git checkout multiple options issue
Date: Mon, 28 Jan 2019 09:29:17 -0800	[thread overview]
Message-ID: <xmqqtvhsbsia.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20190128165515.GA25995@alpha> (Kevin Daudt's message of "Mon, 28 Jan 2019 17:55:15 +0100")

Kevin Daudt <me@ikke.info> writes:

> On Mon, Jan 28, 2019 at 10:20:02AM -0500, Randall S. Becker wrote:
>> On January 28, 2019 9:25, COLLOMB Joris wrote:
>> ...
>> > git checkout -f -b "branch_name"
>> > gives me " Fatal: A branch named 'branch_name' already exists."
>> 
>> Once the branch is created, you can't force its creation, because it is
>> already created. Just
>> 
>> git checkout "branch_name"
>> 
>> is sufficient at this point. git is correct to complain that you are trying
>> to create a branch that already exists.
>
> git checkout -B exists, which does exactly that: force create a branch
> at a new positon if it already exists.

Correct.

"git checkout -b/-B" is for lazy people to perform two things,
i.e. "creating a branch" and "checking the branch out", at the same
time.

If we did not allow "git checkout -b newbranch othercommit" and only
allowed "git checkout -b newbranch", i.e. to start a branch at the
current HEAD, then we could make "git checkout -f -b newbranch" to
mean "git checkout -B newbranch", because creating a branch at HEAD
and checking it out will not have a risk of overwriting local
changes, i.e. no need to force the "checking the branch out" part,
so the "--force" option can only mean "force creating the branch".

But because the new branch can begin at the commit whose tree
differs at a path that has local modifications, there needs a way to
tell the command which part, either "creating a branch" or "checking
the branch out", is being forced.  Hence, "-f" tells the "checking
out the branch" part to do the forcing (e.g. allowing local changes
to be overwritten), and "creating a branch" part is told to force
with the distinction between "-b" and "-B".




      reply	other threads:[~2019-01-28 17:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-28 13:25 Git checkout multiple options issue COLLOMB Joris -EXT
2019-01-28 14:12 ` Randall S. Becker
2019-01-28 14:24   ` COLLOMB Joris -EXT
2019-01-28 15:20     ` Randall S. Becker
2019-01-28 16:02       ` COLLOMB Joris -EXT
2019-01-28 16:37         ` Randall S. Becker
2019-01-28 16:55       ` Kevin Daudt
2019-01-28 17:29         ` Junio C Hamano [this message]

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=xmqqtvhsbsia.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=joris.collomb-ext@alstomgroup.com \
    --cc=me@ikke.info \
    --cc=rsbecker@nexbridge.com \
    /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).