Sparse-checkout configuration persists across workflows on self-hosted runners
[Bug] Sparse-checkout settings from actions/checkout persist and affect subsequent workflows on self-hosted runners
Summary
When using actions/checkout with sparse-checkout on a self-hosted runner, the sparse-checkout Git configuration persists across subsequent jobs. This causes later workflows (that do not use sparse-checkout) to only check out the previously sparse file set instead of the full repository.
Prerequisite
- A self-hosted GitHub Actions runner is configured and available.
Steps to Reproduce
-
Run a workflow with sparse-checkout
- name: Checkout specific file from sample-repo uses: actions/checkout@v4 with: lfs: true repository: org-name/sample-repo token: ${{ secrets.SAMPLE_TOKEN }} # Contains a PAT path: sample-repo sparse-checkout: | sample-file.bak sparse-checkout-cone-mode: false clean: falseAllow the workflow to complete.
-
Run a second workflow on the same self-hosted runner (no sparse-checkout):
- uses: actions/checkout@v4 with: clean: true
Expected Behavior
The second workflow should check out the entire repository, unaffected by the sparse-checkout configuration from the previous workflow.
Actual Behavior
- The second workflow:
- Removes all files.
- Only checks out the files that were previously specified in the sparse-checkout configuration from the first workflow.
- This indicates that
core.sparseCheckoutremains set totruein the runner’s Git configuration between jobs.
Analysis
- The
actions/checkoutaction modifies the runner’s Git config:git config core.sparseCheckout true - On self-hosted runners, this configuration persists across jobs and workflows.
- Unless explicitly reset, future runs on that runner inherit the sparse-checkout state.
Temporary Workaround
Manually disable sparse-checkout after using it:
- name: Disable sparse checkout
run: git config core.sparseCheckout false
continue-on-error: true
Proposed Fix
Ensure actions/checkout:
- Resets
core.sparseCheckouttofalseat the start of each execution. - Does not persist sparse-checkout state between runs on the same runner.
Reproducibility
- 100% reproducible.
- Can be tested without relying on our workflow execution references.
Environment
actions/checkout: v4- Runner type: Self-hosted
- OS: Windows
We just stumbled upon the same problem (action Version 4.2.2). Here is our research:
- The issue is linked to the usage of non cone mode checkouts. In that case,
core.sparseCheckoutis enabled directly, without callinggit sparse-checkout. - At some point (we are not sure how this happens),
extensions.worktreeConfigis enabled - During
git sparse-checkout disable, git setscore.sparseCheckouttofalsein.git/config.worktree!!! - Afterwards,
extensions.worktreeConfigis disabled: https://github.com/actions/checkout/blob/ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493/src/git-command-manager.ts#L182 - This leaves behind a
core.sparseCheckout=truein.git/configcausing further checkouts in the worktree/repository to use the sparse configuration
I can think of two ways to solve this:
- Switch https://github.com/actions/checkout/blob/ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493/src/git-command-manager.ts#L182 with Line 180, maybe ensure that
core.sparseCheckoutisfalseby explicitly setting it. - Don't set
core.sparseCheckoutmanually but initialize the sparse checkout for non cone mode withgit sparse-checkoutaswell and trust thatgitis doing the correct thing.
Thanks for reporting this. We’ve confirmed the behavior and will be working on a fix so that actions/checkout properly restores the sparse-checkout state in the post step.
Hello, we are running into the same situation as listed above. Curious if there are any updates?
Chiming in to say that we are experiencing this issue as well. Using sparse-checkout-cone-mode: true fixed the issue for us.
Bug is reproducible on Linux as well
Same here with actions/[email protected] (3d3c42e) and git 2.53 on self-hosted Ubuntu 26.04 runners, and we traced the exact sequence.
Job 1, sparse-checkout: <two files> with sparse-checkout-cone-mode: false. The log shows:
git config core.sparseCheckout true
git rev-parse --git-path info/sparse-checkout # the action writes the patterns there itself
git checkout --progress --force <sha>
So core.sparseCheckout true goes into .git/config, and extensions.worktreeConfig isn't involved.
Job 2, a plain checkout of the same repo on the same runner (clean: true, no sparse inputs):
git sparse-checkout disable
git config --local --unset-all extensions.worktreeConfig
git checkout --progress --force refs/remotes/pull/<n>/merge
git sparse-checkout disable turns on extensions.worktreeConfig and writes core.sparseCheckout = false to .git/config.worktree. The next command unsets extensions.worktreeConfig, so git stops reading config.worktree, and the true in .git/config applies again. Every later checkout writes only the old patterns. Here that was 2 of 3,523 tracked files, the other 3,521 marked skip-worktree, so make found no Makefile.
The same steps with git alone, which also reproduce it on git 2.56:
git init -q r && cd r && echo a > Makefile && echo b > keep && git add . && git -c user.name=t -c user.email=t@t commit -qm init
git config core.sparseCheckout true && echo keep > .git/info/sparse-checkout && git checkout -q --force HEAD
git sparse-checkout disable && git config --local --unset-all extensions.worktreeConfig && git checkout -q --force HEAD
ls # keep: Makefile is still missing
git config --show-origin core.sparseCheckout # file:.git/config true
Unsetting core.sparseCheckout in .git/config too (not only in config.worktree), or running disable after extensions.worktreeConfig is unset, would fix it. Until then, we've stopped using sparse-checkout on persistent runners.
We hit the same disable-then-unset sequence @jnvai describes, with actions/checkout@11d5960a326750d5838078e36cf38b85af677262 on the v4 line, git 2.43.0, and a self-hosted Linux runner that reuses its repository checkout. After a non-cone sparse checkout, the next checkout without sparse inputs left 376 of 381 index entries marked skip-worktree.
One more observation: sparseCheckoutNonConeMode appends to info/sparse-checkout instead of replacing it. So while that file is kept, successive non-cone checkouts pile up their patterns. Ours held the patterns of three different jobs, separated by blank lines.
The open PR #2034 adds git config core.sparseCheckout false to disableSparseCheckout, which addresses the disable path described here. It does not change the appending.
Separately, remote.origin.promisor=true and remote.origin.partialclonefilter=blob:none were also left in the config, which matches #2601.