Skip to content

Make orphaned commit checks configurable - #2264

Open
wyatt-holden wants to merge 3 commits into
gitgitgadget:masterfrom
wyatt-holden:wyattholden/checkout-orphaned-commit-warning
Open

wyatt-holden wants to merge 3 commits into
gitgitgadget:masterfrom
wyatt-holden:wyattholden/checkout-orphaned-commit-warning

Conversation

@wyatt-holden

@wyatt-holden wyatt-holden commented Oct 16, 2026 •

Copy link
Copy Markdown

Hi there - my name's Wyatt Holden and I'm a Software Engineer at Microsoft :) I've been working with Derrick Stolee over the past few weeks on optimizing git in the Office mono-repo. We found some issues around slow checkouts on mono-repos in an automated environment:

When leaving a detached HEAD, git checkout and git switch call orphaned_commit_warning() to warn about commits that are not reachable from any existing ref or the destination HEAD. This requires enumerating refs and walking commit history, which can be expensive in large repositories.

In an internal mono-repo, Trace2 showed tree unpacking finishing approximately 12 seconds into a roughly 204-second checkout. Stack samples captured the main thread inside  orphaned_commit_warning() , enumerating loose refs and opening ref files. Running checkout with  --quiet , which bypasses this routine, reduced the observed runtime to approximately 14 seconds. These observations identify ref enumeration as a contributor but do not establish how much time was spent enumerating refs versus traversing history. They motivate an opt-out without ruling out improvements to the check itself. However,  --quiet  also suppresses local-change summaries, HEAD and branch-switch messages, and upstream tracking information.

This three-commit series adds a targeted opt-out, advertises it when the check is slow, and enables it in Scalar:

  1. checkout: make orphaned commit checks configurable
    Add  checkout.orphanedCommitWarning , enabled by default, and  --[no-]orphaned-commit-warning  for both checkout and switch. The command-line options override the configuration;  --quiet  continues to skip the check regardless of those options. Disabling the check retains the previous HEAD description and normal checkout output. Add a Trace2 region to expose the check's duration and tests verifying configuration and command-line overrides, retained output, and that disabling the check bypasses the routine rather than merely hiding its warning.
  2. checkout: advise when orphaned commit checks are slow
    When the check takes more than two seconds, suggest  --no-orphaned-commit-warning  or  checkout.orphanedCommitWarning=false  and explain that disabling the check also removes the warning about commits left behind. Control this advice independently through  advice.checkoutOrphanedCommitWarning . Test advice and suppression without relying on wall-clock delays.
  3. scalar: disable orphaned commit checks by default
    Add  checkout.orphanedCommitWarning=false  to Scalar's recommended configuration using its existing set-if-missing mechanism, preserving explicit user settings during clone, register, and reconfigure. Document the tradeoff and reflog recovery; rely on existing Scalar tests for configuration-preservation behavior.

Ordinary Git retains its existing default behavior. Users who disable the check lose the immediate warning about commits left behind; those commits can still be recovered through the HEAD reflog while the relevant entries and objects remain available.

Changes since v1:
• Add  --[no-]orphaned-commit-warning  to checkout and switch, with documentation and tests covering configuration overrides and interaction with  --quiet .
• Mention the command-line opt-out in the slow-check advice and its documentation.
• Relax the shared advice-command test to allow options such as  --global , while still checking the literal configuration key and  false  value.
• Correct the alignment of the new entry in  advice.c . The Scalar patch is unchanged.

CC: gitster@pobox.com, stolee@gmail.com, wyattj.holden@gmail.com

@gitgitgadget

gitgitgadget Bot commented Oct 16, 2026

Copy link
Copy Markdown

Welcome to GitGitGadget

Hi @wyatt-holden, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests.

Please make sure that either:

  • Your Pull Request has a good description, if it consists of multiple commits, as it will be used as cover letter.
  • Your Pull Request description is empty, if it consists of a single commit, as the commit message should be descriptive enough by itself.

You can CC potential reviewers by adding a footer to the PR description with the following syntax:

CC: Revi Ewer <revi.ewer@example.com>, Ill Takalook <ill.takalook@example.net>

NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description,
because it will result in a malformed CC list on the mailing list. See
example.

Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:

  • the lines should not exceed 76 columns,
  • the first line should be like a header and typically start with a prefix like "tests:" or "revisions:" to state which subsystem the change is about, and
  • the commit messages' body should be describing the "why?" of the change.
  • Finally, the commit messages should end in a Signed-off-by: line matching the commits' author.

It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code.

Contributing the patches

Before you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form /allow. A good way to find other contributors is to locate recent pull requests where someone has been /allowed:

Both the person who commented /allow and the PR author are able to /allow you.

An alternative is the channel #git-devel on the Libera Chat IRC network:

<newcontributor> I've just created my first PR, could someone please /allow me? https://github.com/gitgitgadget/git/pull/12345
<veteran> newcontributor: it is done
<newcontributor> thanks!

Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment /submit.

If you want to see what email(s) would be sent for a /submit request, add a PR comment /preview to have the email(s) sent to you. You must have a public GitHub email address for this. Note that any reviewers CC'd via the list in the PR description will not actually be sent emails.

After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail).

If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the (raw) link), then import it into your mail program. If you use GMail, you can do this via:

curl -g --user "<EMailAddress>:<Password>" \
    --url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt

To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):

Changes since v1:
- Fixed a typo in the commit message (found by ...)
- Added a code comment to ... as suggested by ...
...

To send a new iteration, just add another PR comment with the contents: /submit.

Need help?

New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join.

You may also be able to find help in real time in the developer IRC channel, #git-devel on Libera Chat. Remember that IRC does not support offline messaging, so if you send someone a private message and log out, they cannot respond to you. The scrollback of #git-devel is archived, though.

@gitgitgadget

gitgitgadget Bot commented Oct 16, 2026

Copy link
Copy Markdown

There is an issue in commit 44df4e9:
checkout: make orphaned commit checks configurable

  • Commit not signed off

@gitgitgadget

gitgitgadget Bot commented Oct 16, 2026

Copy link
Copy Markdown

There is an issue in commit 00d3fc0:
scalar: disable orphaned commit checks by default

  • Commit not signed off

@wyatt-holden
wyatt-holden force-pushed the wyattholden/checkout-orphaned-commit-warning branch from 00d3fc0 to 8d9f70d Compare October 16, 2026 19:08
@gitgitgadget

gitgitgadget Bot commented Oct 16, 2026

Copy link
Copy Markdown

There is an issue in commit 1e3e99b:
checkout: make orphaned commit checks configurable

  • Commit not signed off

@gitgitgadget

gitgitgadget Bot commented Oct 16, 2026

Copy link
Copy Markdown

There is an issue in commit 8d9f70d:
scalar: disable orphaned commit checks by default

  • Commit not signed off

@wyatt-holden
wyatt-holden force-pushed the wyattholden/checkout-orphaned-commit-warning branch 2 times, most recently from b4c882f to 76d29a1 Compare October 16, 2026 19:44
@dscho

dscho commented Oct 17, 2026

Copy link
Copy Markdown
Member

/allow

@gitgitgadget

gitgitgadget Bot commented Oct 17, 2026

Copy link
Copy Markdown

User wyatt-holden is now allowed to use GitGitGadget.

WARNING: wyatt-holden has no public email address set on GitHub; GitGitGadget needs an email address to Cc: you on your contribution, so that you receive any feedback on the Git mailing list. Go to https://github.com/settings/profile to make your preferred email public to let GitGitGadget know which email address to use.

@derrickstolee

Copy link
Copy Markdown

/allow

@gitgitgadget

gitgitgadget Bot commented Oct 19, 2026

Copy link
Copy Markdown

User wyatt-holden already allowed to use GitGitGadget.

@derrickstolee derrickstolee left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some recommendations, but here are some top-level thoughts:

  1. You use your @microsoft.com email address, but we can't use that to reply to the mailing list. Have you subscribed to the mailing list somewhere? (I use my Gmail account, have a rule to put the mailing list messages in a folder, and use Thunderbird to navigate and reply to those messages in plaintext.)

  2. Your cover letter could include an introduction of yourself (and I'll chime in to vouch for you). But be sure that any justification of the change also happens in the commit messages. You'll want to add cc: gitster@pobox.com and cc: stolee@gmail.com to CC the maintainer and me.

  3. "In an affected Scalar-managed repository" you could say "In an internal monorepo" as this could impact a non-Scalar repo. I do wonder how much Scalar and the GVFS Protocol could have impacted this situation, but probably the repo didn't have a commit-graph file (yet) which would have sped-up this check. It might be worth spending some time to understand what exactly was slow about it: did the client use the full endpoint and thus was walking from a huge list of refs? Was it missing commits and thus downloading thousands of missing commits one-by-one? (that last one won't really impact upstream Git clients) It can be worth mentioning that this was something in an automated environment, so we didn't care about abandoning the detached HEAD commit. Users might want to know this information, but I suspect that most ignore it and aren't willing to wait for it.

  4. You should mention these two commits directly (and in this format):

06b324c1d71 (status: add status.aheadbehind setting, 2019-06-18)
0a53561a622 (status: warn when a/b calculation takes too long, 2019-06-18)

One thing that is different between those two changes and your change is that git status got a --no-ahead-behind argument that is referenced by the warning, but you're only adding a config option. I think that this is the right call, but it might be worth pointing out that difference as something you know about and is open for changing if reviewers think it's important.

Comment thread builtin/checkout.c Resolved
Comment thread builtin/checkout.c Resolved
Comment thread t/t2020-checkout-detach.sh Resolved
Comment thread t/t9210-scalar.sh Resolved
@wyatt-holden

wyatt-holden commented Oct 20, 2026 •

Copy link
Copy Markdown
Author

I have some recommendations, but here are some top-level thoughts:

  1. You use your @microsoft.com email address, but we can't use that to reply to the mailing list. Have you subscribed to the mailing list somewhere? (I use my Gmail account, have a rule to put the mailing list messages in a folder, and use Thunderbird to navigate and reply to those messages in plaintext.)
  2. Your cover letter could include an introduction of yourself (and I'll chime in to vouch for you). But be sure that any justification of the change also happens in the commit messages. You'll want to add cc: gitster@pobox.com and cc: stolee@gmail.com to CC the maintainer and me.
  3. "In an affected Scalar-managed repository" you could say "In an internal monorepo" as this could impact a non-Scalar repo. I do wonder how much Scalar and the GVFS Protocol could have impacted this situation, but probably the repo didn't have a commit-graph file (yet) which would have sped-up this check. It might be worth spending some time to understand what exactly was slow about it: did the client use the full endpoint and thus was walking from a huge list of refs? Was it missing commits and thus downloading thousands of missing commits one-by-one? (that last one won't really impact upstream Git clients) It can be worth mentioning that this was something in an automated environment, so we didn't care about abandoning the detached HEAD commit. Users might want to know this information, but I suspect that most ignore it and aren't willing to wait for it.
  4. You should mention these two commits directly (and in this format):
06b324c1d71 (status: add status.aheadbehind setting, 2019-06-18)
0a53561a622 (status: warn when a/b calculation takes too long, 2019-06-18)

One thing that is different between those two changes and your change is that git status got a --no-ahead-behind argument that is referenced by the warning, but you're only adding a config option. I think that this is the right call, but it might be worth pointing out that difference as something you know about and is open for changing if reviewers think it's important.

@derrickstolee -
1 - Okay - just got done subscribing on wyattj.holden@gmail.com. I'll CC myself in the cover/PR description as well
2 - Okay, got it - I'll push modified commits soon
3 - After looking through my PR, it looks like i was using the full endpoint - so this could explain a large number of refs being populated locally on the machine? Though, I'm not entirely sure if the commit-graph file existed or not from the dumps/logs i still do have.
But we for sure know that enumerating on loose ref files was happening. we captured dumps at 15 (2-3 seconds after unpack_trees completed), 45, and 75 seconds into the checkout process, and orpahned_commit_warning() is in all three of the dumps main thread - showing filesystem operations are happening on loose ref files (opening, reading and closing them).
4. Cool, I'll mention those in the modified commit messages

@wyatt-holden
wyatt-holden force-pushed the wyattholden/checkout-orphaned-commit-warning branch from 76d29a1 to f24d401 Compare October 20, 2026 15:45
@wyatt-holden

Copy link
Copy Markdown
Author

/submit

@gitgitgadget

gitgitgadget Bot commented Nov 5, 2026

Copy link
Copy Markdown

Error: Could not determine full name of wyatt-holden

@wyatt-holden

Copy link
Copy Markdown
Author

/submit

@gitgitgadget

gitgitgadget Bot commented Nov 10, 2026

Copy link
Copy Markdown

Submitted as pull.2264.git.1794337920.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2264/wyatt-holden/wyattholden/checkout-orphaned-commit-warning-v1

To fetch this version to local tag pr-2264/wyatt-holden/wyattholden/checkout-orphaned-commit-warning-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2264/wyatt-holden/wyattholden/checkout-orphaned-commit-warning-v1

WARNING: wyatt-holden has no public email address set on GitHub; GitGitGadget needs an email address to Cc: you on your contribution, so that you receive any feedback on the Git mailing list. Go to https://github.com/settings/profile to make your preferred email public to let GitGitGadget know which email address to use.

@@ -38,6 +38,12 @@ all advice messages.
configuration variable for how to set a given remote

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Derrick Stolee wrote on the Git mailing list (how to reply to this email):

On 11/10/2026 2:11 PM, Wyatt Holden via GitGitGadget wrote:

>  	[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] 	= { "checkoutAmbiguousRemoteBranchName" },
> +	[ADVICE_CHECKOUT_ORPHANED_COMMIT_WARNING]		= { "checkoutOrphanedCommitWarning" },
>  	[ADVICE_COMMIT_BEFORE_MERGE]			= { "commitBeforeMerge" },

It looks like we have a slight whitespace alignment problem here.

Thanks,
-Stolee

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

Derrick Stolee <stolee@gmail.com> writes:

> On 11/10/2026 2:11 PM, Wyatt Holden via GitGitGadget wrote:
>
>>  	[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] 	= { "checkoutAmbiguousRemoteBranchName" },
>> +	[ADVICE_CHECKOUT_ORPHANED_COMMIT_WARNING]		= { "checkoutOrphanedCommitWarning" },
>>  	[ADVICE_COMMIT_BEFORE_MERGE]			= { "commitBeforeMerge" },
>
> It looks like we have a slight whitespace alignment problem here.
>
> Thanks,
> -Stolee

Good eyes.  What the patch aims does sound sensible to me, though.

@gitgitgadget

gitgitgadget Bot commented Nov 10, 2026

Copy link
Copy Markdown

Derrick Stolee wrote on the Git mailing list (how to reply to this email):

On 11/10/2026 2:11 PM, Wyatt Holden via GitGitGadget wrote:
> Hi there - my name's Wyatt Holden and I'm a Software Engineer at Microsoft
> :) I've been working with Derrick Stolee over the past few weeks on
> optimizing git in the Office mono-repo. We found some issues around slow
> checkouts on mono-repos in an automated environment:

Welcome, Wyatt! (I was prepared for your series.) 
> When leaving a detached HEAD, git checkout and git switch
> call orphaned_commit_warning() to warn about commits that are not reachable
> from any existing ref or the destination HEAD. This requires enumerating
> refs and walking commit history, which can be expensive in large
> repositories.
> 
> In an internal mono-repo, Trace2 showed tree unpacking finishing
> approximately 12 seconds into checkout, but the process continuing for
> roughly another 193 seconds. A stack dump captured the main thread inside
>  orphaned_commit_warning(), enumerating loose refs and opening ref files.
> Running checkout with --quiet, which bypasses this routine, reduced the
> observed runtime to approximately 14 seconds. However, --quiet also
> suppresses unrelated output.

This example shows a significant pain caused by this check, but we also
want to be able to see progress indicators over time in our logs, so
using --quiet isn't preferred, long term.

> This three-commit series adds a targeted opt-out, advertises it when the
> check is slow, and enables it in Scalar:

I did some pre-review with Wyatt (but found one nitpick in my on-list
re-review) so I'm biased. Further bias: I recommended that he follow
the model of the status.aheadBehind config [1] and advice.statusAheadBehind
[2] patches as prior art.

[1] https://lore.kernel.org/git/2f0f2a2df9410947b985d83a924d2549d62bb65f.1560889284.git.gitgitgadget@gmail.com/

[2] https://lore.kernel.org/git/c1056545b617b89e881f5991beb2fe0d860de740.1560889284.git.gitgitgadget@gmail.com/

And also I added status.aheadBehind to Scalar's recommended config in
its very first version [3]. Wyatt has updated the Scalar config docs
that justify the recommendation, which was introduced only recently [4].

[3] https://lore.kernel.org/git/4439ab4de0bc3f48a6bdcf4b5165b16fad792ebd.1638538470.git.gitgitgadget@gmail.com/

[4] https://lore.kernel.org/git/f062b0e0773b9d168c031bb1f35538665394a077.1765552528.git.gitgitgadget@gmail.com/

So I give my support publicly for Wyatt's updates.

Thanks,
-Stolee

@@ -22,6 +22,17 @@ commands or functionality in the future.
option in `git checkout` and `git switch`. See

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Wyatt Holden via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Wyatt Holden <wyattholden@microsoft.com>
>
> When leaving a detached HEAD, checkout enumerates refs and walks
> history to warn about commits left behind. This work can dominate
> checkout time even after the working tree has been updated.

Interesting.

I often am on a detached HEAD but never realized this particular
check was expensive.  The size of changes between the HEAD and the
next branch would affect the time it needs to update the working
tree (the larger the difference, the more expensive to complete the
branch switching).  What factors are involved in making this
"orphaned commits" check more expensive?  The total number of
branches?  The length of commit chain we are leaving behind?  I am
trying to see if this is something we can aim to optimize or if it
is a lost cause and a cop-out to introduce an option to disable the
check altogether is the best we can do.

> In an automated checkout of an internal monorepo, unpack_trees ended
> about 12 seconds into a roughly 204-second run. Stack dumps captured
> the main thread in orphaned_commit_warning(), enumerating loose refs
> and opening ref files. Using --quiet reduced the observed checkout
> time to about 14 seconds, but also suppressed unrelated output.
> These observations motivate an opt-out; they do not establish how
> much of the delay came from enumeration versus history traversal.

So, in short, the answer to my earlier question is "we don't know".

> Add checkout.orphanedCommitWarning, enabled by default, so checkout
> and switch can skip the check while retaining normal checkout output.
> Automated callers can opt out when they do not need a warning about
> leaving detached commits behind.

Sounds sensible.

> Follow the configuration precedent of 06b324c1d71 (status: add
> status.aheadbehind setting, 2019-06-18). Unlike status, introduce no
> dedicated command-line option; callers can use git -c for a one-off
> override.

I am not sure how justifiable the design decision to leave the
command line option out is.

The automation can run with "-q" to omit the overhead altogether, as
well as squelching any other output the automation would not read
anyway, so I would not worry too much about them.

But for human users, what are they losing by passing "-q" when they
do not want to pay the cost of this check because we are not giving
them an easy to use command line option?  What other output are they
declining by "--quiet"?  "The following paths have local changes"
list?  Anything else?

> Add a Trace2 region around the check to make its cost visible in
> future investigations and to verify that disabling the setting skips
> the routine rather than merely hiding its warning. Document the
> setting and test both checkout and switch.

Sounds sensible.

> @@ -1132,6 +1134,7 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne
>  	struct rev_info revs;
>  	struct object *object = &old_commit->object;
>  
> +	trace2_region_enter("checkout", "orphaned_commit_warning", the_repository);
>  	repo_init_revisions(the_repository, &revs, NULL);
>  	setup_revisions(0, NULL, &revs, NULL);
>  
> @@ -1155,6 +1158,7 @@ static void orphaned_commit_warning(struct commit *old_commit, struct commit *ne
>  	/* Clean up objects used, as they will be reused. */
>  	repo_clear_commit_marks(the_repository, ALL_REV_FLAGS);
>  	release_revisions(&revs);
> +	trace2_region_leave("checkout", "orphaned_commit_warning", the_repository);
>  }


Quite straightforward.  There is no early return in the middle, so
entering at the beginning with leaving at the end is the only change
necessary.

> @@ -1253,8 +1257,14 @@ static int switch_branches(const struct checkout_opts *opts,
>  		}
>  	}
>  
> -	if (!opts->quiet && !old_branch_info.path && old_branch_info.commit && new_branch_info->commit != old_branch_info.commit)
> -		orphaned_commit_warning(old_branch_info.commit, new_branch_info->commit);
> +	if (!opts->quiet && !old_branch_info.path && old_branch_info.commit &&
> +	    new_branch_info->commit != old_branch_info.commit) {
> +		if (opts->orphaned_commit_warning)
> +			orphaned_commit_warning(old_branch_info.commit, new_branch_info->commit);
> +		else
> +			describe_detached_head(_("Previous HEAD position was"),
> +					       old_branch_info.commit);
> +	}

OK.  The call into suggest_reattach() via orphaned_commit_warning()
is the more expensive part, and it also is where "Previous HEAD
was" comes, which we do not want to lose.  It makes sense.

Another thing I noticed is that the loop in suggest_reattach() stops
showing each commit after showing ORPHAN_CUTOFF but keeps counting.
I wonder if it becomes palatable to introduce a configuration to
stop it early, instead of disabling the orphaned_commit_warning()
altogether?

@gitgitgadget

gitgitgadget Bot commented Nov 10, 2026

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Wyatt Holden via GitGitGadget" <gitgitgadget@gmail.com> writes:

> When leaving a detached HEAD, git checkout and git switch
> call orphaned_commit_warning() to warn about commits that are not reachable
> from any existing ref or the destination HEAD. This requires enumerating
> refs and walking commit history, which can be expensive in large
> repositories.

I found some design choices made in 1/3 questionable but overall the
series is coherently done and very easy to understand _why_ it wants
to do what it does.  Nice work.

Wyatt Holden added 3 commits November 11, 2026 15:31
When leaving a detached HEAD, checkout enumerates refs and walks
history to warn about commits left behind. This work can dominate
checkout time even after the working tree has been updated.

In an automated checkout of an internal monorepo, unpack_trees ended
about 12 seconds into a roughly 204-second run. Stack dumps captured
the main thread in orphaned_commit_warning(), enumerating loose refs
and opening ref files. Using --quiet reduced the observed checkout
time to about 14 seconds. These observations do not establish how
much of the delay came from enumeration versus history traversal.

However, --quiet also suppresses local-change summaries, HEAD and
branch-switch messages, and upstream tracking information.

Add checkout.orphanedCommitWarning, enabled by default, and
--[no-]orphaned-commit-warning to checkout and switch. Let the command
line override the configuration while preserving --quiet's existing
behavior. Callers can then skip the check without suppressing other
checkout output.

Follow the configuration and command-line precedent of 06b324c
(status: add status.aheadbehind setting, 2019-06-18).

Add a Trace2 region to expose the check's duration and verify that
disabling it skips the work rather than merely hiding its warning.
Test both commands, configuration overrides, and retained output.

Signed-off-by: Wyatt Holden <wyattholden@microsoft.com>
Users encountering a slow orphaned-commit check need a way to
discover how to skip it without suppressing other checkout output.

Measure the complete check and suggest --no-orphaned-commit-warning
or checkout.orphanedCommitWarning=false when it takes more than two
seconds. Explain that skipping the check also removes the warning
about commits left behind. Allow the advice itself to be disabled
with advice.checkoutOrphanedCommitWarning.

Follow 0a53561 (status: warn when a/b calculation takes too long,
2019-06-18).

Add a test hook that forces the advice condition without changing
the measured duration. Test advice suppression independently of the
orphan warning, and tolerate scope options in the shared advice's
suggested configuration command.

Signed-off-by: Wyatt Holden <wyattholden@microsoft.com>
Checking for commits left behind when leaving a detached HEAD can
be expensive in large repositories. Add
checkout.orphanedCommitWarning=false to Scalar's recommended settings
to avoid this foreground work while preserving normal checkout output.

Use the existing set-if-missing behavior so explicit user choices are
preserved during clone, register, and reconfigure. Document the loss
of the immediate orphan warning and the availability of reflog
recovery. Existing Scalar tests cover configuration preservation,
so no additional inventory of recommended settings is needed.

Signed-off-by: Wyatt Holden <wyattholden@microsoft.com>
@wyatt-holden
wyatt-holden force-pushed the wyattholden/checkout-orphaned-commit-warning branch from f24d401 to 89792a3 Compare November 11, 2026 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants