{"thread":{"id":"66823","subject":"[PATCH 0/3] Make orphaned commit checks configurable","startedAt":"2026-11-10T19:11:57Z","lastAt":"2026-11-11T18:52:32Z","messageCount":10,"participants":["Wyatt Holden via GitGitGadget","Derrick Stolee","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"558129","messageId":"pull.2264.git.1794337920.gitgitgadget@gmail.com","threadId":"66823","inReplyTo":null,"subject":"[PATCH 0/3] Make orphaned commit checks configurable","fromName":"Wyatt Holden via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-10T19:11:57Z","receivedAt":"2026-11-10T19:11:57Z","isPatch":true,"sender":{"key":"name:Wyatt Holden","avatar":null},"body":"Hi there - my name's Wyatt Holden and I'm a Software Engineer at Microsoft\n:) I've been working with Derrick Stolee over the past few weeks on\noptimizing git in the Office mono-repo. We found some issues around slow\ncheckouts on mono-repos in an automated environment:\n\nWhen leaving a detached HEAD, git checkout and git switch\ncall orphaned_commit_warning() to warn about commits that are not reachable\nfrom any existing ref or the destination HEAD. This requires enumerating\nrefs and walking commit history, which can be expensive in large\nrepositories.\n\nIn an internal mono-repo, Trace2 showed tree unpacking finishing\napproximately 12 seconds into checkout, but the process continuing for\nroughly another 193 seconds. A stack dump captured the main thread inside\n orphaned_commit_warning(), enumerating loose refs and opening ref files.\nRunning checkout with --quiet, which bypasses this routine, reduced the\nobserved runtime to approximately 14 seconds. However, --quiet also\nsuppresses unrelated output.\n\nThis three-commit series adds a targeted opt-out, advertises it when the\ncheck is slow, and enables it in Scalar:\n\n 1. checkout: make orphaned commit checks configurable Add\n     checkout.orphanedCommitWarning , enabled by default, for both checkout\n    and switch. Setting it to  false  skips the reachability check while\n    retaining the previous HEAD description and normal checkout output. Add\n    a Trace2 region to expose the check’s duration and tests verifying that\n    disabling the setting bypasses the routine.\n 2. checkout: advise when orphaned commit checks are slow When the check\n    takes more than two seconds, suggest the opt-out and explain that\n    disabling it also removes the warning about commits left behind. Control\n    this advice independently through advice.checkoutOrphanedCommitWarning.\n    Test advice and suppression without relying on wall-clock delays.\n 3. scalar: disable orphaned commit checks by default Add\n    checkout.orphanedCommitWarning=false to Scalar’s recommended\n    configuration using its existing set-if-missing mechanism, preserving\n    explicit user settings during clone, register, and reconfigure. Document\n    the tradeoff and reflog recovery; rely on existing Scalar tests for\n    configuration-preservation behavior.\n\nOrdinary Git retains its existing default behavior. Users who disable the\ncheck lose the immediate warning about commits left behind; those commits\ncan still be recovered through the HEAD reflog while the relevant entries\nand objects remain available.\n\nWyatt Holden (3):\n  checkout: make orphaned commit checks configurable\n  checkout: advise when orphaned commit checks are slow\n  scalar: disable orphaned commit checks by default\n\n Documentation/config/advice.adoc   |  6 +++\n Documentation/config/checkout.adoc | 11 +++++\n Documentation/scalar.adoc          |  7 +++\n advice.c                           |  1 +\n advice.h                           |  1 +\n builtin/checkout.c                 | 31 +++++++++++++-\n scalar.c                           |  1 +\n t/README                           |  5 +++\n t/t2020-checkout-detach.sh         | 69 ++++++++++++++++++++++++++++++\n 9 files changed, 130 insertions(+), 2 deletions(-)\n\n\nbase-commit: 6de20f6092dcf9bdb1c8efe03db4b70c82b423dd\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2264%2Fwyatt-holden%2Fwyattholden%2Fcheckout-orphaned-commit-warning-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2264/wyatt-holden/wyattholden/checkout-orphaned-commit-warning-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2264\n-- \ngitgitgadget\n\n"},{"id":"558130","messageId":"6aad1a1cd34a65939be6f64a0d8950e0bc23870a.1794337920.git.gitgitgadget@gmail.com","threadId":"66823","inReplyTo":"pull.2264.git.1794337920.gitgitgadget@gmail.com","subject":"[PATCH 1/3] checkout: make orphaned commit checks configurable","fromName":"Wyatt Holden via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-10T19:11:58Z","receivedAt":"2026-11-10T19:11:58Z","isPatch":true,"sender":{"key":"name:Wyatt Holden","avatar":null},"body":"From: Wyatt Holden <wyattholden@microsoft.com>\n\nWhen leaving a detached HEAD, checkout enumerates refs and walks\nhistory to warn about commits left behind. This work can dominate\ncheckout time even after the working tree has been updated.\n\nIn an automated checkout of an internal monorepo, unpack_trees ended\nabout 12 seconds into a roughly 204-second run. Stack dumps captured\nthe main thread in orphaned_commit_warning(), enumerating loose refs\nand opening ref files. Using --quiet reduced the observed checkout\ntime to about 14 seconds, but also suppressed unrelated output.\nThese observations motivate an opt-out; they do not establish how\nmuch of the delay came from enumeration versus history traversal.\n\nAdd checkout.orphanedCommitWarning, enabled by default, so checkout\nand switch can skip the check while retaining normal checkout output.\nAutomated callers can opt out when they do not need a warning about\nleaving detached commits behind.\n\nFollow the configuration precedent of 06b324c1d71 (status: add\nstatus.aheadbehind setting, 2019-06-18). Unlike status, introduce no\ndedicated command-line option; callers can use git -c for a one-off\noverride.\n\nAdd a Trace2 region around the check to make its cost visible in\nfuture investigations and to verify that disabling the setting skips\nthe routine rather than merely hiding its warning. Document the\nsetting and test both checkout and switch.\n\nSigned-off-by: Wyatt Holden <wyattholden@microsoft.com>\n---\n Documentation/config/checkout.adoc | 11 +++++++++++\n builtin/checkout.c                 | 18 ++++++++++++++++--\n t/t2020-checkout-detach.sh         | 29 +++++++++++++++++++++++++++++\n 3 files changed, 56 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/config/checkout.adoc b/Documentation/config/checkout.adoc\nindex e35d212969..cacd10449a 100644\n--- a/Documentation/config/checkout.adoc\n+++ b/Documentation/config/checkout.adoc\n@@ -22,6 +22,17 @@ commands or functionality in the future.\n \toption in `git checkout` and `git switch`. See\n \tlinkgit:git-switch[1] and linkgit:git-checkout[1].\n \n+`checkout.orphanedCommitWarning`::\n+\tWhen leaving a detached `HEAD`, linkgit:git-checkout[1] and\n+\tlinkgit:git-switch[1] check whether any commits are being left\n+\tbehind that are not reachable from any ref or the new `HEAD`,\n+\tand warn if so. This check can be expensive in large repositories.\n+\tSet this variable to `false` to skip the check and its warning\n+\twithout suppressing other checkout output. Defaults to `true`.\n++\n+When disabled, commits left behind can still be found in the `HEAD`\n+reflog until its entries expire. See linkgit:git-reflog[1].\n+\n `checkout.workers`::\n \tThe number of parallel workers to use when updating the working tree.\n \tThe default is one, i.e. sequential execution. If set to a value less\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex c0f0d2c700..7cc9e97612 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -51,6 +51,7 @@ struct checkout_opts {\n \tint patch_interhunk_context;\n \tint auto_advance;\n \tint quiet;\n+\tint orphaned_commit_warning;\n \tint merge;\n \tint force;\n \tint force_detach;\n@@ -99,6 +100,7 @@ struct checkout_opts {\n \t.patch_context = -1, \\\n \t.patch_interhunk_context = -1, \\\n \t.auto_advance = 1, \\\n+\t.orphaned_commit_warning = 1, \\\n }\n \n #define MERGE_WORKING_TREE_UNPACK_FAILED (-2)\n@@ -1132,6 +1134,7 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne\n \tstruct rev_info revs;\n \tstruct object *object = &old_commit->object;\n \n+\ttrace2_region_enter(\"checkout\", \"orphaned_commit_warning\", the_repository);\n \trepo_init_revisions(the_repository, &revs, NULL);\n \tsetup_revisions(0, NULL, &revs, NULL);\n \n@@ -1155,6 +1158,7 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne\n \t/* Clean up objects used, as they will be reused. */\n \trepo_clear_commit_marks(the_repository, ALL_REV_FLAGS);\n \trelease_revisions(&revs);\n+\ttrace2_region_leave(\"checkout\", \"orphaned_commit_warning\", the_repository);\n }\n \n static int switch_branches(const struct checkout_opts *opts,\n@@ -1253,8 +1257,14 @@ static int switch_branches(const struct checkout_opts *opts,\n \t\t}\n \t}\n \n-\tif (!opts->quiet && !old_branch_info.path && old_branch_info.commit && new_branch_info->commit != old_branch_info.commit)\n-\t\torphaned_commit_warning(old_branch_info.commit, new_branch_info->commit);\n+\tif (!opts->quiet && !old_branch_info.path && old_branch_info.commit &&\n+\t    new_branch_info->commit != old_branch_info.commit) {\n+\t\tif (opts->orphaned_commit_warning)\n+\t\t\torphaned_commit_warning(old_branch_info.commit, new_branch_info->commit);\n+\t\telse\n+\t\t\tdescribe_detached_head(_(\"Previous HEAD position was\"),\n+\t\t\t\t\t       old_branch_info.commit);\n+\t}\n \n \tif (autostash_res == STASH_APPLY_CONFLICT && !opts->quiet)\n \t\tfputc('\\n', stderr);\n@@ -1295,6 +1305,10 @@ static int git_checkout_config(const char *var, const char *value,\n \t\topts->dwim_new_local_branch = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"checkout.orphanedcommitwarning\")) {\n+\t\topts->orphaned_commit_warning = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \tif (starts_with(var, \"submodule.\"))\n \t\treturn git_default_submodule_config(var, value, NULL);\ndiff --git a/t/t2020-checkout-detach.sh b/t/t2020-checkout-detach.sh\nindex 28bbbe6c05..d21dbd5b72 100755\n--- a/t/t2020-checkout-detach.sh\n+++ b/t/t2020-checkout-detach.sh\n@@ -164,6 +164,35 @@ test_expect_success 'checkout does not warn leaving reachable commit' '\n \tcheck_no_orphan_warning stderr\n '\n \n+for command in checkout switch\n+do\n+\ttest_expect_success \"$command honors checkout.orphanedCommitWarning\" '\n+\t\tgit checkout --detach \"$orphan2\" &&\n+\t\tGIT_TRACE2_EVENT=\"$(pwd)/trace-enabled-$command\" \\\n+\t\t\tgit -c checkout.orphanedCommitWarning=true \\\n+\t\t\t$command main 2>stderr &&\n+\t\tcheck_orphan_warning stderr \"2 commits\" &&\n+\t\ttest_grep \"\\\"label\\\":\\\"orphaned_commit_warning\\\"\" \\\n+\t\t\ttrace-enabled-$command &&\n+\n+\t\tgit checkout --detach \"$orphan2\" &&\n+\t\tGIT_TRACE2_EVENT=\"$(pwd)/trace-disabled-$command\" \\\n+\t\t\tgit -c checkout.orphanedCommitWarning=false \\\n+\t\t\t$command main 2>stderr &&\n+\t\tcheck_no_orphan_warning stderr &&\n+\t\ttest_grep \"Switched to branch\" stderr &&\n+\t\ttest_grep ! \"\\\"label\\\":\\\"orphaned_commit_warning\\\"\" \\\n+\t\t\ttrace-disabled-$command &&\n+\t\tcheck_not_detached\n+\t'\n+\n+\ttest_expect_success \"$command rejects invalid checkout.orphanedCommitWarning\" '\n+\t\ttest_must_fail git -c checkout.orphanedCommitWarning=invalid \\\n+\t\t\t$command main 2>stderr &&\n+\t\ttest_grep \"bad boolean config value.*checkout.orphanedcommitwarning\" stderr\n+\t'\n+done\n+\n cat >expect <<'EOF'\n Your branch is behind 'main' by 1 commit, and can be fast-forwarded.\n   (use \"git pull\" to update your local branch)\n-- \ngitgitgadget\n\n\n"},{"id":"558131","messageId":"a9b81eb87684fa9bfbc83e845eb67ded8d7cb6d9.1794337920.git.gitgitgadget@gmail.com","threadId":"66823","inReplyTo":"pull.2264.git.1794337920.gitgitgadget@gmail.com","subject":"[PATCH 2/3] checkout: advise when orphaned commit checks are slow","fromName":"Wyatt Holden via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-10T19:11:59Z","receivedAt":"2026-11-10T19:11:59Z","isPatch":true,"sender":{"key":"name:Wyatt Holden","avatar":null},"body":"From: Wyatt Holden <wyattholden@microsoft.com>\n\nThe orphaned-commit check can take much longer than updating the\nworking tree. Users who encounter this cost need a way to discover\nthe checkout.orphanedCommitWarning setting.\n\nMeasure the complete check and suggest disabling it when it takes\nmore than two seconds. Explain that opting out also removes the\nwarning about commits left behind, and allow the advice itself to be\ndisabled with advice.checkoutOrphanedCommitWarning.\n\nFollow the slow-operation advice introduced by:\n\n0a53561a622 (status: warn when a/b calculation takes too long, 2019-06-18)\n\nUnlike that status advice, recommend a configuration setting rather\nthan a dedicated command-line option.\n\nKeep a test hook to exercise advice and suppression without relying\non wall-clock delays. Force the advice condition without replacing\nthe measured duration, and check the formatted duration rather than\na fabricated fixed value.\n\nSigned-off-by: Wyatt Holden <wyattholden@microsoft.com>\n---\n Documentation/config/advice.adoc |  6 +++++\n advice.c                         |  1 +\n advice.h                         |  1 +\n builtin/checkout.c               | 13 +++++++++++\n t/README                         |  5 ++++\n t/t2020-checkout-detach.sh       | 40 ++++++++++++++++++++++++++++++++\n 6 files changed, 66 insertions(+)\n\ndiff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc\nindex 3d91c90eda..eecf72d8d1 100644\n--- a/Documentation/config/advice.adoc\n+++ b/Documentation/config/advice.adoc\n@@ -38,6 +38,12 @@ all advice messages.\n \t\tconfiguration variable for how to set a given remote\n \t\tto be used by default in some situations where this\n \t\tadvice would be printed.\n+\tcheckoutOrphanedCommitWarning::\n+\t\tShown when linkgit:git-checkout[1] or linkgit:git-switch[1]\n+\t\ttakes more than 2 seconds to check for commits left behind\n+\t\twhen leaving a detached `HEAD`. Suggests setting\n+\t\t`checkout.orphanedCommitWarning` to `false` to skip the check.\n+\t\tDisabling this advice does not disable the check itself.\n \tcommitBeforeMerge::\n \t\tShown when linkgit:git-merge[1] refuses to\n \t\tmerge to avoid overwriting local changes.\ndiff --git a/advice.c b/advice.c\nindex 401d047391..8142d73b5e 100644\n--- a/advice.c\n+++ b/advice.c\n@@ -50,6 +50,7 @@ static struct {\n \t[ADVICE_AMBIGUOUS_FETCH_REFSPEC]\t\t= { \"ambiguousFetchRefspec\" },\n \t[ADVICE_AM_WORK_DIR] \t\t\t\t= { \"amWorkDir\" },\n \t[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] \t= { \"checkoutAmbiguousRemoteBranchName\" },\n+\t[ADVICE_CHECKOUT_ORPHANED_COMMIT_WARNING]\t\t= { \"checkoutOrphanedCommitWarning\" },\n \t[ADVICE_COMMIT_BEFORE_MERGE]\t\t\t= { \"commitBeforeMerge\" },\n \t[ADVICE_DEFAULT_BRANCH_NAME]\t\t\t= { \"defaultBranchName\" },\n \t[ADVICE_DETACHED_HEAD]\t\t\t\t= { \"detachedHead\" },\ndiff --git a/advice.h b/advice.h\nindex 3f0b4f0485..7dd1fe109c 100644\n--- a/advice.h\n+++ b/advice.h\n@@ -17,6 +17,7 @@ enum advice_type {\n \tADVICE_AMBIGUOUS_FETCH_REFSPEC,\n \tADVICE_AM_WORK_DIR,\n \tADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME,\n+\tADVICE_CHECKOUT_ORPHANED_COMMIT_WARNING,\n \tADVICE_COMMIT_BEFORE_MERGE,\n \tADVICE_DEFAULT_BRANCH_NAME, /* To be retired sometime after Git 3.0 */\n \tADVICE_DETACHED_HEAD,\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 7cc9e97612..1e94280d35 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -35,6 +35,7 @@\n #include \"strvec.h\"\n #include \"submodule.h\"\n #include \"symlinks.h\"\n+#include \"trace.h\"\n #include \"trace2.h\"\n #include \"tree.h\"\n #include \"tree-walk.h\"\n@@ -1133,6 +1134,8 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne\n {\n \tstruct rev_info revs;\n \tstruct object *object = &old_commit->object;\n+\tuint64_t t_begin = getnanotime();\n+\tuint64_t t_delta_in_ms;\n \n \ttrace2_region_enter(\"checkout\", \"orphaned_commit_warning\", the_repository);\n \trepo_init_revisions(the_repository, &revs, NULL);\n@@ -1159,6 +1162,16 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne\n \trepo_clear_commit_marks(the_repository, ALL_REV_FLAGS);\n \trelease_revisions(&revs);\n \ttrace2_region_leave(\"checkout\", \"orphaned_commit_warning\", the_repository);\n+\n+\tt_delta_in_ms = (getnanotime() - t_begin) / 1000000;\n+\tif (t_delta_in_ms > 2000 ||\n+\t    git_env_bool(\"GIT_TEST_CHECKOUT_DELAY_WARNING\", 0))\n+\t\tadvise_if_enabled(ADVICE_CHECKOUT_ORPHANED_COMMIT_WARNING,\n+\t\t\t\t  _(\"Checking for orphaned commits took %.2f seconds.\\n\"\n+\t\t\t\t    \"You can use 'git config set checkout.orphanedCommitWarning false'\\n\"\n+\t\t\t\t    \"to skip this check, but you will no longer be warned when leaving\\n\"\n+\t\t\t\t    \"commits behind that are not connected to any of your branches.\"),\n+\t\t\t\t  t_delta_in_ms / 1000.0);\n }\n \n static int switch_branches(const struct checkout_opts *opts,\ndiff --git a/t/README b/t/README\nindex fd7e8504b5..577f02732e 100644\n--- a/t/README\n+++ b/t/README\n@@ -371,6 +371,11 @@ test suite. Accept any boolean values that are accepted by git-config.\n GIT_TEST_PROTOCOL_VERSION=<n>, when set, makes 'protocol.version'\n default to n.\n \n+GIT_TEST_CHECKOUT_DELAY_WARNING=<boolean>, when true, forces the\n+slow orphaned-commit check advice to be considered regardless of the\n+elapsed time. It does not change the measured duration or override\n+advice settings.\n+\n GIT_TEST_FULL_IN_PACK_ARRAY=<boolean> exercises the uncommon\n pack-objects code path where there are more than 1024 packs even if\n the actual number of packs in repository is below this limit. Accept\ndiff --git a/t/t2020-checkout-detach.sh b/t/t2020-checkout-detach.sh\nindex d21dbd5b72..7dfaaab1b8 100755\n--- a/t/t2020-checkout-detach.sh\n+++ b/t/t2020-checkout-detach.sh\n@@ -186,6 +186,46 @@ do\n \t\tcheck_not_detached\n \t'\n \n+\ttest_expect_success \"$command advises when the orphan check is slow\" '\n+\t\tgit checkout --detach \"$orphan2\" &&\n+\t\tGIT_TEST_CHECKOUT_DELAY_WARNING=true \\\n+\t\t\tgit $command main 2>stderr &&\n+\t\tcheck_orphan_warning stderr \"2 commits\" &&\n+\t\ttest_grep -E \"^hint: Checking for orphaned commits took [0-9]+[.][0-9]{2} seconds[.]$\" stderr &&\n+\t\ttest_grep \"git config set checkout.orphanedCommitWarning false\" stderr &&\n+\t\ttest_grep \"git config set advice.checkoutOrphanedCommitWarning false\" stderr\n+\t'\n+\n+\ttest_expect_success \"$command can suppress slow orphan check advice\" '\n+\t\tgit checkout --detach \"$orphan2\" &&\n+\t\tGIT_TEST_CHECKOUT_DELAY_WARNING=true \\\n+\t\t\tgit -c advice.checkoutOrphanedCommitWarning=false \\\n+\t\t\t$command main 2>stderr &&\n+\t\tcheck_orphan_warning stderr \"2 commits\" &&\n+\t\ttest_grep ! \"^hint:\" stderr &&\n+\n+\t\tgit checkout --detach \"$orphan2\" &&\n+\t\tGIT_TEST_CHECKOUT_DELAY_WARNING=true GIT_ADVICE=0 \\\n+\t\t\tgit $command main 2>stderr &&\n+\t\tcheck_orphan_warning stderr \"2 commits\" &&\n+\t\ttest_grep ! \"^hint:\" stderr\n+\t'\n+\n+\ttest_expect_success \"$command does not advise when the orphan check is skipped\" '\n+\t\tgit checkout --detach \"$orphan2\" &&\n+\t\tGIT_TEST_CHECKOUT_DELAY_WARNING=true \\\n+\t\t\tgit -c checkout.orphanedCommitWarning=false \\\n+\t\t\t$command main 2>stderr &&\n+\t\tcheck_no_orphan_warning stderr &&\n+\t\ttest_grep ! \"^hint:\" stderr &&\n+\n+\t\tgit checkout --detach \"$orphan2\" &&\n+\t\tGIT_TEST_CHECKOUT_DELAY_WARNING=true \\\n+\t\t\tgit $command --quiet main 2>stderr &&\n+\t\ttest_must_be_empty stderr &&\n+\t\tcheck_not_detached\n+\t'\n+\n \ttest_expect_success \"$command rejects invalid checkout.orphanedCommitWarning\" '\n \t\ttest_must_fail git -c checkout.orphanedCommitWarning=invalid \\\n \t\t\t$command main 2>stderr &&\n-- \ngitgitgadget\n\n\n"},{"id":"558132","messageId":"f24d4019e889b12cd6237217c3cf31f47aa318d5.1794337920.git.gitgitgadget@gmail.com","threadId":"66823","inReplyTo":"pull.2264.git.1794337920.gitgitgadget@gmail.com","subject":"[PATCH 3/3] scalar: disable orphaned commit checks by default","fromName":"Wyatt Holden via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-10T19:12:00Z","receivedAt":"2026-11-10T19:12:00Z","isPatch":true,"sender":{"key":"name:Wyatt Holden","avatar":null},"body":"From: Wyatt Holden <wyattholden@microsoft.com>\n\nChecking for commits left behind when leaving a detached HEAD can\nbe expensive in large repositories. Add\ncheckout.orphanedCommitWarning=false to Scalar's recommended settings\nto avoid this foreground work while preserving normal checkout output.\n\nUse the existing set-if-missing behavior so explicit user choices\nare preserved during clone, register, and reconfigure. Document the\nloss of the immediate orphan warning and the availability of reflog\nrecovery. Existing Scalar tests cover configuration preservation,\nso no additional inventory of recommended settings is needed.\n\nSigned-off-by: Wyatt Holden <wyattholden@microsoft.com>\n---\n Documentation/scalar.adoc | 7 +++++++\n scalar.c                  | 1 +\n 2 files changed, 8 insertions(+)\n\ndiff --git a/Documentation/scalar.adoc b/Documentation/scalar.adoc\nindex 5252fb134a..d2b8c9a6ca 100644\n--- a/Documentation/scalar.adoc\n+++ b/Documentation/scalar.adoc\n@@ -214,6 +214,13 @@ am.keepCR=true::\n \tand non-Windows platforms and keeping carriage return (`\\r`) characters\n \tin certain workflows.\n \n+checkout.orphanedCommitWarning=false::\n+\tThis disables the reachability check that warns about commits left\n+\tbehind when `git checkout` or `git switch` leaves a detached `HEAD`.\n+\tThe check can be expensive in large repositories. Other checkout\n+\toutput is unchanged, and commits left behind can still be found\n+\tin the `HEAD` reflog until its entries expire.\n+\n commitGraph.changedPaths=true::\n \tThis setting helps the background maintenance steps that compute the\n \tserialized commit-graph to also store changed-path Bloom filters. This\ndiff --git a/scalar.c b/scalar.c\nindex a80d8ee3ff..7f851f5610 100644\n--- a/scalar.c\n+++ b/scalar.c\n@@ -138,6 +138,7 @@ static int set_recommended_config(int reconfigure)\n \t */\n \tstruct scalar_config config[] = {\n \t\t{ \"am.keepCR\", \"true\" },\n+\t\t{ \"checkout.orphanedCommitWarning\", \"false\" },\n \t\t{ \"commitGraph.changedPaths\", \"true\" },\n \t\t{ \"commitGraph.generationVersion\", \"1\" },\n \t\t{ \"core.autoCRLF\", \"false\" },\n-- \ngitgitgadget\n\n"},{"id":"558144","messageId":"90f09054-9013-46f6-b4de-9be88d1f3126@gmail.com","threadId":"66823","inReplyTo":"a9b81eb87684fa9bfbc83e845eb67ded8d7cb6d9.1794337920.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 2/3] checkout: advise when orphaned commit checks are slow","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2026-11-10T20:48:58Z","receivedAt":"2026-11-10T20:48:58Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 11/10/2026 2:11 PM, Wyatt Holden via GitGitGadget wrote:\n\n>  \t[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] \t= { \"checkoutAmbiguousRemoteBranchName\" },\n> +\t[ADVICE_CHECKOUT_ORPHANED_COMMIT_WARNING]\t\t= { \"checkoutOrphanedCommitWarning\" },\n>  \t[ADVICE_COMMIT_BEFORE_MERGE]\t\t\t= { \"commitBeforeMerge\" },\n\nIt looks like we have a slight whitespace alignment problem here.\n\nThanks,\n-Stolee\n\n\n"},{"id":"558145","messageId":"dd253dfe-446e-4f2d-bd00-95ebc529cbc1@gmail.com","threadId":"66823","inReplyTo":"pull.2264.git.1794337920.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/3] Make orphaned commit checks configurable","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2026-11-10T20:57:54Z","receivedAt":"2026-11-10T20:57:54Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 11/10/2026 2:11 PM, Wyatt Holden via GitGitGadget wrote:\n> Hi there - my name's Wyatt Holden and I'm a Software Engineer at Microsoft\n> :) I've been working with Derrick Stolee over the past few weeks on\n> optimizing git in the Office mono-repo. We found some issues around slow\n> checkouts on mono-repos in an automated environment:\n\nWelcome, Wyatt! (I was prepared for your series.) \n> When leaving a detached HEAD, git checkout and git switch\n> call orphaned_commit_warning() to warn about commits that are not reachable\n> from any existing ref or the destination HEAD. This requires enumerating\n> refs and walking commit history, which can be expensive in large\n> repositories.\n> \n> In an internal mono-repo, Trace2 showed tree unpacking finishing\n> approximately 12 seconds into checkout, but the process continuing for\n> roughly another 193 seconds. A stack dump captured the main thread inside\n>  orphaned_commit_warning(), enumerating loose refs and opening ref files.\n> Running checkout with --quiet, which bypasses this routine, reduced the\n> observed runtime to approximately 14 seconds. However, --quiet also\n> suppresses unrelated output.\n\nThis example shows a significant pain caused by this check, but we also\nwant to be able to see progress indicators over time in our logs, so\nusing --quiet isn't preferred, long term.\n\n> This three-commit series adds a targeted opt-out, advertises it when the\n> check is slow, and enables it in Scalar:\n\nI did some pre-review with Wyatt (but found one nitpick in my on-list\nre-review) so I'm biased. Further bias: I recommended that he follow\nthe model of the status.aheadBehind config [1] and advice.statusAheadBehind\n[2] patches as prior art.\n\n[1] https://lore.kernel.org/git/2f0f2a2df9410947b985d83a924d2549d62bb65f.1560889284.git.gitgitgadget@gmail.com/\n\n[2] https://lore.kernel.org/git/c1056545b617b89e881f5991beb2fe0d860de740.1560889284.git.gitgitgadget@gmail.com/\n\nAnd also I added status.aheadBehind to Scalar's recommended config in\nits very first version [3]. Wyatt has updated the Scalar config docs\nthat justify the recommendation, which was introduced only recently [4].\n\n[3] https://lore.kernel.org/git/4439ab4de0bc3f48a6bdcf4b5165b16fad792ebd.1638538470.git.gitgitgadget@gmail.com/\n\n[4] https://lore.kernel.org/git/f062b0e0773b9d168c031bb1f35538665394a077.1765552528.git.gitgitgadget@gmail.com/\n\nSo I give my support publicly for Wyatt's updates.\n\nThanks,\n-Stolee\n\n\n"},{"id":"558147","messageId":"xmqqa4ngpcjq.fsf@gitster.g","threadId":"66823","inReplyTo":"6aad1a1cd34a65939be6f64a0d8950e0bc23870a.1794337920.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 1/3] checkout: make orphaned commit checks configurable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-10T22:05:45Z","receivedAt":"2026-11-10T22:05:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Wyatt Holden via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Wyatt Holden <wyattholden@microsoft.com>\n>\n> When leaving a detached HEAD, checkout enumerates refs and walks\n> history to warn about commits left behind. This work can dominate\n> checkout time even after the working tree has been updated.\n\nInteresting.\n\nI often am on a detached HEAD but never realized this particular\ncheck was expensive.  The size of changes between the HEAD and the\nnext branch would affect the time it needs to update the working\ntree (the larger the difference, the more expensive to complete the\nbranch switching).  What factors are involved in making this\n\"orphaned commits\" check more expensive?  The total number of\nbranches?  The length of commit chain we are leaving behind?  I am\ntrying to see if this is something we can aim to optimize or if it\nis a lost cause and a cop-out to introduce an option to disable the\ncheck altogether is the best we can do.\n\n> In an automated checkout of an internal monorepo, unpack_trees ended\n> about 12 seconds into a roughly 204-second run. Stack dumps captured\n> the main thread in orphaned_commit_warning(), enumerating loose refs\n> and opening ref files. Using --quiet reduced the observed checkout\n> time to about 14 seconds, but also suppressed unrelated output.\n> These observations motivate an opt-out; they do not establish how\n> much of the delay came from enumeration versus history traversal.\n\nSo, in short, the answer to my earlier question is \"we don't know\".\n\n> Add checkout.orphanedCommitWarning, enabled by default, so checkout\n> and switch can skip the check while retaining normal checkout output.\n> Automated callers can opt out when they do not need a warning about\n> leaving detached commits behind.\n\nSounds sensible.\n\n> Follow the configuration precedent of 06b324c1d71 (status: add\n> status.aheadbehind setting, 2019-06-18). Unlike status, introduce no\n> dedicated command-line option; callers can use git -c for a one-off\n> override.\n\nI am not sure how justifiable the design decision to leave the\ncommand line option out is.\n\nThe automation can run with \"-q\" to omit the overhead altogether, as\nwell as squelching any other output the automation would not read\nanyway, so I would not worry too much about them.\n\nBut for human users, what are they losing by passing \"-q\" when they\ndo not want to pay the cost of this check because we are not giving\nthem an easy to use command line option?  What other output are they\ndeclining by \"--quiet\"?  \"The following paths have local changes\"\nlist?  Anything else?\n\n> Add a Trace2 region around the check to make its cost visible in\n> future investigations and to verify that disabling the setting skips\n> the routine rather than merely hiding its warning. Document the\n> setting and test both checkout and switch.\n\nSounds sensible.\n\n> @@ -1132,6 +1134,7 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne\n>  \tstruct rev_info revs;\n>  \tstruct object *object = &old_commit->object;\n>  \n> +\ttrace2_region_enter(\"checkout\", \"orphaned_commit_warning\", the_repository);\n>  \trepo_init_revisions(the_repository, &revs, NULL);\n>  \tsetup_revisions(0, NULL, &revs, NULL);\n>  \n> @@ -1155,6 +1158,7 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne\n>  \t/* Clean up objects used, as they will be reused. */\n>  \trepo_clear_commit_marks(the_repository, ALL_REV_FLAGS);\n>  \trelease_revisions(&revs);\n> +\ttrace2_region_leave(\"checkout\", \"orphaned_commit_warning\", the_repository);\n>  }\n\n\nQuite straightforward.  There is no early return in the middle, so\nentering at the beginning with leaving at the end is the only change\nnecessary.\n\n> @@ -1253,8 +1257,14 @@ static int switch_branches(const struct checkout_opts *opts,\n>  \t\t}\n>  \t}\n>  \n> -\tif (!opts->quiet && !old_branch_info.path && old_branch_info.commit && new_branch_info->commit != old_branch_info.commit)\n> -\t\torphaned_commit_warning(old_branch_info.commit, new_branch_info->commit);\n> +\tif (!opts->quiet && !old_branch_info.path && old_branch_info.commit &&\n> +\t    new_branch_info->commit != old_branch_info.commit) {\n> +\t\tif (opts->orphaned_commit_warning)\n> +\t\t\torphaned_commit_warning(old_branch_info.commit, new_branch_info->commit);\n> +\t\telse\n> +\t\t\tdescribe_detached_head(_(\"Previous HEAD position was\"),\n> +\t\t\t\t\t       old_branch_info.commit);\n> +\t}\n\nOK.  The call into suggest_reattach() via orphaned_commit_warning()\nis the more expensive part, and it also is where \"Previous HEAD\nwas\" comes, which we do not want to lose.  It makes sense.\n\nAnother thing I noticed is that the loop in suggest_reattach() stops\nshowing each commit after showing ORPHAN_CUTOFF but keeps counting.\nI wonder if it becomes palatable to introduce a configuration to\nstop it early, instead of disabling the orphaned_commit_warning()\naltogether?\n\n"},{"id":"558150","messageId":"xmqq5wy4pbsh.fsf@gitster.g","threadId":"66823","inReplyTo":"90f09054-9013-46f6-b4de-9be88d1f3126@gmail.com","subject":"Re: [PATCH 2/3] checkout: advise when orphaned commit checks are slow","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-10T22:22:06Z","receivedAt":"2026-11-10T22:22:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Derrick Stolee <stolee@gmail.com> writes:\n\n> On 11/10/2026 2:11 PM, Wyatt Holden via GitGitGadget wrote:\n>\n>>  \t[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] \t= { \"checkoutAmbiguousRemoteBranchName\" },\n>> +\t[ADVICE_CHECKOUT_ORPHANED_COMMIT_WARNING]\t\t= { \"checkoutOrphanedCommitWarning\" },\n>>  \t[ADVICE_COMMIT_BEFORE_MERGE]\t\t\t= { \"commitBeforeMerge\" },\n>\n> It looks like we have a slight whitespace alignment problem here.\n>\n> Thanks,\n> -Stolee\n\nGood eyes.  What the patch aims does sound sensible to me, though.\n\n"},{"id":"558151","messageId":"xmqq1p8spbg5.fsf@gitster.g","threadId":"66823","inReplyTo":"pull.2264.git.1794337920.gitgitgadget@gmail.com","subject":"Re: [PATCH 0/3] Make orphaned commit checks configurable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-10T22:29:30Z","receivedAt":"2026-11-10T22:29:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Wyatt Holden via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> When leaving a detached HEAD, git checkout and git switch\n> call orphaned_commit_warning() to warn about commits that are not reachable\n> from any existing ref or the destination HEAD. This requires enumerating\n> refs and walking commit history, which can be expensive in large\n> repositories.\n\nI found some design choices made in 1/3 questionable but overall the\nseries is coherently done and very easy to understand _why_ it wants\nto do what it does.  Nice work.\n\n\n"},{"id":"558245","messageId":"xmqqtslnmc9b.fsf@gitster.g","threadId":"66823","inReplyTo":"a9b81eb87684fa9bfbc83e845eb67ded8d7cb6d9.1794337920.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 2/3] checkout: advise when orphaned commit checks are slow","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-11T18:52:32Z","receivedAt":"2026-11-11T18:52:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Wyatt Holden via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> diff --git a/t/t2020-checkout-detach.sh b/t/t2020-checkout-detach.sh\n> index d21dbd5b72..7dfaaab1b8 100755\n> --- a/t/t2020-checkout-detach.sh\n> +++ b/t/t2020-checkout-detach.sh\n> @@ -186,6 +186,46 @@ do\n>  \t\tcheck_not_detached\n>  \t'\n>  \n> +\ttest_expect_success \"$command advises when the orphan check is slow\" '\n> +\t\tgit checkout --detach \"$orphan2\" &&\n> +\t\tGIT_TEST_CHECKOUT_DELAY_WARNING=true \\\n> +\t\t\tgit $command main 2>stderr &&\n> +\t\tcheck_orphan_warning stderr \"2 commits\" &&\n> +\t\ttest_grep -E \"^hint: Checking for orphaned commits took [0-9]+[.][0-9]{2} seconds[.]$\" stderr &&\n> +\t\ttest_grep \"git config set checkout.orphanedCommitWarning false\" stderr &&\n> +\t\ttest_grep \"git config set advice.checkoutOrphanedCommitWarning false\" stderr\n> +\t'\n\nThis test will not pass in the modern world where the advice message\nsuggests to use \"git config set --global advice.FOO false\".\n\nIt probably makes sense to grep for something looser like\n\n\t\"git config .* advice\\.checkoutOrphanedCommitWarning\"\n\n\n\n\n\n"}]}