Re: [PATCH] checkout: add --fetch to fetch remote before resolving start-point On 24/04/2026 11:03 am, Harald Nordgren via GitGitGadget wrote: Show 10 quoted lines > 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
> start-point argument names a configured remote (either bare, like
> "origin", or prefixed, like "origin/foo"), fetch that remote before
> resolving the ref. Aborts the checkout if the fetch fails.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> --- Show 60 quoted lines >
> diff --git a/t/t7201-co.sh b/t/t7201-co.sh
> index 9bcf7c0b40..60ddebd9c3 100755
> --- a/t/t7201-co.sh
> +++ b/t/t7201-co.sh
> @@ -801,4 +801,55 @@ test_expect_success 'tracking info copied with autoSetupMerge=inherit' '
> test_cmp_config "" --default "" branch.main2.merge
> '
>
> +test_expect_success 'setup upstream for --fetch tests' '
> + git checkout main &&
> + git init fetch_upstream &&
> + test_commit -C fetch_upstream u_main &&
> + git remote add fetch_upstream fetch_upstream &&
> + git fetch fetch_upstream &&
> + git -C fetch_upstream checkout -b fetch_new &&
> + test_commit -C fetch_upstream u_new
> +'
> +
> +test_expect_success 'checkout --fetch -b picks up branch created upstream after clone' '
> + git checkout main &&
> + test_must_fail git rev-parse --verify refs/remotes/fetch_upstream/fetch_new &&
> + git checkout --fetch -b local_new fetch_upstream/fetch_new &&
> + test_cmp_rev refs/remotes/fetch_upstream/fetch_new HEAD
> +'
> +
> +test_expect_success 'checkout --fetch with bare remote name fetches the remote' '
> + git checkout main &&
> + git -C fetch_upstream checkout -b fetch_new2 &&
> + test_commit -C fetch_upstream u_new2 &&
> + test_must_fail git rev-parse --verify refs/remotes/fetch_upstream/fetch_new2 &&
> + git checkout --fetch -b local_from_remote fetch_upstream &&
> + git rev-parse --verify refs/remotes/fetch_upstream/fetch_new2
> +'
> +
> +test_expect_success 'checkout --fetch aborts and does not create branch on fetch failure' '
> + git checkout main &&
> + test_might_fail git branch -D bogus &&
> + test_must_fail git checkout --fetch -b bogus fetch_upstream/does_not_exist &&
> + test_must_fail git rev-parse --verify refs/heads/bogus
> +'
> +
> +test_expect_success 'checkout.autoFetch=true enables fetching without --fetch' '
> + git checkout main &&
> + git -C fetch_upstream checkout -b fetch_cfg &&
> + test_commit -C fetch_upstream u_cfg &&
> + test_must_fail git rev-parse --verify refs/remotes/fetch_upstream/fetch_cfg &&
> + git -c checkout.autoFetch=true checkout -b local_cfg fetch_upstream/fetch_cfg &&
> + test_cmp_rev refs/remotes/fetch_upstream/fetch_cfg HEAD
> +'
> +
> +test_expect_success 'switch --fetch -c picks up branch created upstream after clone' '
> + git checkout main &&
> + git -C fetch_upstream checkout -b fetch_switch &&
> + test_commit -C fetch_upstream u_switch &&
> + test_must_fail git rev-parse --verify refs/remotes/fetch_upstream/fetch_switch &&
> + git switch --fetch -c local_switch fetch_upstream/fetch_switch &&
> + test_cmp_rev refs/remotes/fetch_upstream/fetch_switch HEAD
> +'
> + I was just skimming the list (so if this is not appropriate, please just ignore) and, although I think '--no-fetch' will probably countermand the autoFetch config, I do not see a test that confirms it.
Thanks. ATB, Ramsay Jones
Message 2 of 73 in “checkout: add --fetch to fetch remote before resolving start-point” checkout: add --fetch to fetch remote before resolving start-point Harald Nordgren via GitGitGadget, Apr 24, 2026 Ramsay Jones Apr 24, 2026 D. Ben Knoble Apr 24, 2026 Kristoffer Haugsbakk Apr 24, 2026 Marc Branchaud Apr 24, 2026 Junio C Hamano Apr 24, 2026 Junio C Hamano Apr 25, 2026 Comments on Phillip's review Harald Nordgren, Apr 25, 2026 Comments on Phillip's review Harald Nordgren, Apr 25, 2026 Wrong subject line Harald Nordgren, Apr 25, 2026 Wrong subject line Harald Nordgren, Apr 25, 2026 Wrong subject line Harald Nordgren, Apr 25, 2026 Multiple remotes Harald Nordgren, Apr 25, 2026 checkout: add --fetch to fetch remote before resolving start-point Harald Nordgren via GitGitGadget, Apr 25, 2026 Ben Knoble Apr 25, 2026 gh Harald Nordgren, Apr 25, 2026 Kristoffer Haugsbakk Apr 26, 2026 checkout: add --fetch to fetch remote before resolving start-point Harald Nordgren via GitGitGadget, Apr 26, 2026 Harald Nordgren Apr 26, 2026 Ramsay Jones Apr 26, 2026 checkout: add --fetch to fetch remote before resolving start-point Harald Nordgren via GitGitGadget, Apr 26, 2026 Junio C Hamano Apr 28, 2026 Harald Nordgren Apr 28, 2026 checkout: extend --track with a "fetch" mode to refresh start-point Harald Nordgren via GitGitGadget, Apr 28, 2026 Junio C Hamano May 3, 2026 checkout: extend --track with a "fetch" mode to refresh start-point Harald Nordgren via GitGitGadget, May 3, 2026 checkout: add --autostash option for branch switching Harald Nordgren, May 3, 2026 checkout: extend --track with a "fetch" mode to refresh start-point Harald Nordgren, May 7, 2026 Phillip Wood May 8, 2026 checkout: add --fetch to fetch remote before resolving start-point Harald Nordgren, May 8, 2026 checkout: extend --track with a "fetch" mode to refresh start-point Harald Nordgren via GitGitGadget, May 8, 2026 Phillip Wood May 11, 2026 checkout: extend --track with a "fetch" mode to refresh start-point Harald Nordgren via GitGitGadget, May 11, 2026 Junio C Hamano May 12, 2026 checkout: extend --track with a "fetch" mode to refresh start-point Harald Nordgren via GitGitGadget, May 12, 2026 checkout: extend --track with a "fetch" mode to refresh start-point Harald Nordgren via GitGitGadget, May 18, 2026 Harald Nordgren May 18, 2026 Junio C Hamano May 19, 2026 Harald Nordgren May 19, 2026 checkout: extend --track with a "fetch" mode to refresh start-point Harald Nordgren via GitGitGadget, May 19, 2026 Junio C Hamano May 19, 2026 Harald Nordgren May 19, 2026 Harald Nordgren May 19, 2026 Junio C Hamano May 19, 2026 Phillip Wood May 21, 2026 checkout: extend --track with a "fetch" mode to refresh start-point Harald Nordgren via GitGitGadget, May 21, 2026 Harald Nordgren May 21, 2026 Junio C Hamano May 21, 2026 Phillip Wood May 21, 2026 Junio C Hamano May 21, 2026 0/2 checkout: --track=fetchHarald Nordgren via GitGitGadget, May 23, 2026 1/2 branch: expose helpers for finding the remote owning a tracking refHarald Nordgren via GitGitGadget, May 23, 2026 2/2 checkout: extend --track with a "fetch" mode to refresh start-pointHarald Nordgren via GitGitGadget, May 23, 2026 Harald Nordgren Jun 13, 2026 Junio C Hamano Jun 17, 2026 Harald Nordgren Jun 17, 2026 Junio C Hamano Jun 18, 2026 Harald Nordgren Jun 18, 2026 Harald Nordgren Jun 18, 2026 0/2 checkout: --track=fetchHarald Nordgren via GitGitGadget, Jun 18, 2026 1/2 branch: expose helpers for finding the remote owning a tracking refHarald Nordgren via GitGitGadget, Jun 18, 2026 2/2 checkout: extend --track with a "fetch" mode to refresh start-pointHarald Nordgren via GitGitGadget, Jun 18, 2026 D. Ben Knoble Jun 18, 2026 Phillip Wood Jun 23, 2026 Harald Nordgren Jun 23, 2026 0/2 checkout: --track=fetchHarald Nordgren via GitGitGadget, Jun 24, 2026 1/2 branch: expose helpers for finding the remote owning a tracking refHarald Nordgren via GitGitGadget, Jun 24, 2026 2/2 checkout: extend --track with a "fetch" mode to refresh start-pointHarald Nordgren via GitGitGadget, Jun 24, 2026 Junio C Hamano Jun 24, 2026 Ben Knoble Jun 25, 2026 Harald Nordgren Jun 25, 2026 Kristofer Karlsson Jun 25, 2026 Junio C Hamano Jul 23, 2026 Read the whole thread , see it on lore , or plain text .