From: "Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com>
To: git@vger.kernel.org, gitgitgadget@gmail.com
Cc: "Harald Nordgren" <haraldnordgren@gmail.com>
Subject: Re: [PATCH] checkout: add --fetch to fetch remote before resolving start-point
Date: Fri, 24 Apr 2026 19:38:28 +0200 [thread overview]
Message-ID: <89f923bf-e5fc-4557-a2f0-d240db07eaf9@app.fastmail.com> (raw)
In-Reply-To: <pull.2281.git.git.1777024991531.gitgitgadget@gmail.com>
On Fri, Apr 24, 2026, at 12:03, Harald Nordgren via GitGitGadget wrote:
> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> Add a --fetch option to git checkout and git switch, plus a
> checkout.autoFetch config to enable it by default. When set and the
Why is the config not `checkout.config`? So it’s named the same as the
option (modulo snake case/camel case which is not relevant here).
> start-point argument names a configured remote (either bare, like
> "origin", or prefixed, like "origin/foo"),
It’s great that it only fetches when you have a remote-tracking branch
or alias for `<remote>/HEAD`. Doing a fetch on every <start-point> would
have been bad.
> fetch that remote before
> resolving the ref. Aborts the checkout if the fetch fails.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
> checkout: add --fetch to fetch remote before resolving start-point
>
> A workflow I run several times a day looks like:
>
> git fetch origin
> git checkout -b new_branch origin/some-branch
>
>
> The first command exists purely to make the second one see an up-to-date
> view of the remote. If I forget it, origin/some-branch points at a stale
> commit, and I end up creating a local branch from the wrong starting
> point.
>
> This series teaches git checkout (and git switch) a new --fetch flag
> that folds the two steps into one:
>
> git checkout --fetch -b new_branch origin/some-branch
The motivation for why this is being proposed maybe might as well go in
the commit message. Maybe that’s just me.
The commit message just says that “this thing is added”. Not why.
>
>
> When the start-point argument names a configured remote — either bare
> (origin, which resolves to the remote's default branch) or in / form —
> git fetch is run before the start-point is resolved. If the fetch fails,
> the checkout aborts and no local branch is created.
>
> A new checkout.autoFetch config option enables the same behavior by
> default, for users who always want it.
>
> Published-As:
> https://github.com/gitgitgadget/git/releases/tag/pr-git-2281%2FHaraldNordgren%2Fcheckout-fetch-start-point-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git
> pr-git-2281/HaraldNordgren/checkout-fetch-start-point-v1
> Pull-Request: https://github.com/git/git/pull/2281
>
> builtin/checkout.c | 48 ++++++++++++++++++++++++++++++++++++++--
> t/t7201-co.sh | 51 +++++++++++++++++++++++++++++++++++++++++++
> t/t9902-completion.sh | 1 +
> 3 files changed, 98 insertions(+), 2 deletions(-)
I guess a later version will have the changes to the documentation.
>
> diff --git a/builtin/checkout.c b/builtin/checkout.c
>[snip]
> argv += n;
> argc -= n;
> } else if (!opts->accept_ref && opts->from_treeish) {
> @@ -2052,6 +2092,8 @@ int cmd_checkout(int argc,
> OPT_BOOL(0, "overlay", &opts.overlay_mode, N_("use overlay mode
> (default)")),
> OPT_BOOL(0, "auto-advance", &opts.auto_advance,
> N_("auto advance to the next file when selecting hunks
> interactively")),
> + OPT_BOOL(0, "fetch", &opts.auto_fetch,
> + N_("fetch from the remote first if <start-point> is a remote-tracking ref")),
s/remote-tracking ref/remote-tracking branch/ ?
git(1) doesn’t have a namespace for tracking refs in general.
> OPT_END()
> };
>
> @@ -2102,6 +2144,8 @@ int cmd_switch(int argc,
> N_("second guess 'git switch <no-such-branch>'")),
> OPT_BOOL(0, "discard-changes", &opts.discard_changes,
> N_("throw away local modifications")),
> + OPT_BOOL(0, "fetch", &opts.auto_fetch,
> + N_("fetch from the remote first if <start-point> is a remote-tracking ref")),
Ditto.
> OPT_END()
> };
>[snip]
next prev parent reply other threads:[~2026-04-24 17:38 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-24 10:03 [PATCH] checkout: add --fetch to fetch remote before resolving start-point Harald Nordgren via GitGitGadget
2026-04-24 13:48 ` Ramsay Jones
2026-04-24 17:12 ` D. Ben Knoble
2026-04-25 17:24 ` Comments on Phillip's review Harald Nordgren
2026-04-25 17:44 ` Wrong subject line Harald Nordgren
2026-04-24 17:38 ` Kristoffer Haugsbakk [this message]
2026-04-25 17:41 ` Comments on Phillip's review Harald Nordgren
2026-04-25 17:44 ` Wrong subject line Harald Nordgren
2026-04-26 7:07 ` Kristoffer Haugsbakk
2026-04-26 15:15 ` [PATCH] remote: add --set-head option to 'git remote add' Harald Nordgren
2026-04-24 17:42 ` [PATCH] checkout: add --fetch to fetch remote before resolving start-point Marc Branchaud
2026-04-25 17:48 ` Wrong subject line Harald Nordgren
2026-04-24 22:21 ` [PATCH] checkout: add --fetch to fetch remote before resolving start-point Junio C Hamano
2026-04-25 2:54 ` Junio C Hamano
2026-04-25 17:58 ` Multiple remotes Harald Nordgren
2026-04-25 21:57 ` Ben Knoble
2026-04-25 22:54 ` gh Harald Nordgren
2026-04-25 18:12 ` [PATCH v2] checkout: add --fetch to fetch remote before resolving start-point Harald Nordgren via GitGitGadget
2026-04-26 7:24 ` [PATCH v3] " Harald Nordgren via GitGitGadget
2026-04-26 15:54 ` Ramsay Jones
2026-04-26 18:32 ` [PATCH v4] " Harald Nordgren via GitGitGadget
2026-04-28 1:47 ` Junio C Hamano
2026-04-28 8:44 ` [PATCH] " Harald Nordgren
2026-04-28 9:03 ` [PATCH v5] checkout: extend --track with a "fetch" mode to refresh start-point Harald Nordgren via GitGitGadget
2026-05-03 20:59 ` Junio C Hamano
2026-05-03 22:32 ` [PATCH] checkout: add --autostash option for branch switching Harald Nordgren
2026-05-03 22:31 ` [PATCH v6] checkout: extend --track with a "fetch" mode to refresh start-point Harald Nordgren via GitGitGadget
2026-05-07 20:12 ` Harald Nordgren
2026-05-08 13:15 ` Phillip Wood
2026-05-08 22:40 ` [PATCH] checkout: add --fetch to fetch remote before resolving start-point Harald Nordgren
2026-05-08 22:52 ` [PATCH v7] checkout: extend --track with a "fetch" mode to refresh start-point Harald Nordgren via GitGitGadget
2026-05-11 13:16 ` Phillip Wood
2026-05-11 13:47 ` [PATCH v8] " Harald Nordgren via GitGitGadget
2026-05-12 0:32 ` Junio C Hamano
2026-05-12 10:55 ` [PATCH v9] " Harald Nordgren via GitGitGadget
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=89f923bf-e5fc-4557-a2f0-d240db07eaf9@app.fastmail.com \
--to=kristofferhaugsbakk@fastmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=haraldnordgren@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.