checkout icon indicating copy to clipboard operation
checkout copied to clipboard

Sparse-checkout configuration persists across workflows on self-hosted runners

Open nilmond010 opened this issue 1 year ago • 7 comments

[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

  1. 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: false
    

    Allow the workflow to complete.

  2. 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.sparseCheckout remains set to true in the runner’s Git configuration between jobs.

Analysis

  • The actions/checkout action 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:

  1. Resets core.sparseCheckout to false at the start of each execution.
  2. 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

nilmond010 avatar Aug 13 '25 12:08 nilmond010

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.sparseCheckout is enabled directly, without calling git sparse-checkout.
  • At some point (we are not sure how this happens), extensions.worktreeConfig is enabled
  • During git sparse-checkout disable, git sets core.sparseCheckout to false in .git/config.worktree!!!
  • Afterwards, extensions.worktreeConfig is disabled: https://github.com/actions/checkout/blob/ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493/src/git-command-manager.ts#L182
  • This leaves behind a core.sparseCheckout=true in .git/config causing further checkouts in the worktree/repository to use the sparse configuration

I can think of two ways to solve this:

  1. Switch https://github.com/actions/checkout/blob/ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493/src/git-command-manager.ts#L182 with Line 180, maybe ensure that core.sparseCheckout is false by explicitly setting it.
  2. Don't set core.sparseCheckout manually but initialize the sparse checkout for non cone mode with git sparse-checkout aswell and trust that git is doing the correct thing.

stefansli avatar Aug 14 '25 12:08 stefansli

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.

lokesh755 avatar Aug 20 '25 07:08 lokesh755

Hello, we are running into the same situation as listed above. Curious if there are any updates?

vandiesel22 avatar Nov 26 '25 02:11 vandiesel22

Chiming in to say that we are experiencing this issue as well. Using sparse-checkout-cone-mode: true fixed the issue for us.

daltonclaybrook avatar Feb 16 '26 21:02 daltonclaybrook

Bug is reproducible on Linux as well

CharlieAtSchneider avatar Apr 28 '26 06:04 CharlieAtSchneider

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.

jnvai avatar Oct 19 '26 09:10 jnvai

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.

exGeni avatar Nov 14 '26 18:11 exGeni