Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Git

Git: Fix a Sparse Checkout That Silently Hides Files You Expect to See in Your Working Directory

- 03.10.26 - ErcanOPAK

🔀 The Files That Were Committed, Tracked, and Nowhere in Sight

Sparse checkout lets a large repository check out only a subset of its directory tree into the working copy, which is genuinely useful on monorepos where nobody needs every folder on disk at once. The trouble is that a sparse-checkout pattern set up for one task – say, checking out only the frontend/ directory – keeps silently applying to every branch switch and pull afterward, so files that are unambiguously committed and tracked in the repository simply never materialize on disk, with no error telling you they were excluded on purpose.

🔎 The Problem

$ git sparse-checkout init --cone
$ git sparse-checkout set frontend

# Weeks later, a teammate asks you to check something in backend/:
$ cat backend/Services/PaymentService.cs
cat: backend/Services/PaymentService.cs: No such file or directory

$ git log -- backend/Services/PaymentService.cs
# Shows full history - the file is absolutely tracked and committed.

$ ls backend/
# Directory doesn't even exist locally - not because it was deleted,
# but because sparse-checkout never materialized it to begin with.

✅ Fix: Check and Adjust the Active Sparse-Checkout Pattern

  • Run git sparse-checkout list to see exactly which paths are currently included – this single command explains most ‘missing file that’s clearly tracked’ confusion instantly.
  • Use git sparse-checkout add followed by the path to bring an additional directory into the working copy without discarding the existing sparse configuration, or git sparse-checkout disable to check out everything again.
  • Document the sparse-checkout setup (in a README or onboarding note) for any repository that uses it, since a teammate who doesn’t know it’s enabled has no reason to suspect their missing file is a configuration choice rather than a real problem.

⚠️ Why This Is Easy to Miss

  • Every normal Git command – status, log, diff – behaves completely normally and shows no indication that the working directory is intentionally incomplete; only a direct attempt to open a specific file reveals anything is missing.
  • A fresh clone of the same repository by someone without sparse-checkout enabled shows every file exactly as expected, which makes the problem look machine-specific or corruption-related rather than a simple configuration difference.

Sparse checkout doesn’t remove a file from Git – it just quietly declines to show it to you, and keeps declining until you ask it which files it’s hiding.

— Version Control Tip

Related posts:

Git: Use Git Hooks to Automate Tasks on Commit, Push, Merge

Git: Use Git Hooks to Automate Tasks on Commit, Push, Merge

Git: Fix a Commit Signature Failing After a Key Expiry Rotation

Git: Fix a Commit Signature Failing After a Key Expiry Rotation

Git: Use git revert Instead of git reset for Shared Branches

Git: Use git revert Instead of git reset for Shared Branches

Views: 23
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

Docker: Fix an ENTRYPOINT and CMD Combination That Silently Ignores Arguments Passed at docker run
SQL Server: Fix a Filtered Index That Gets Silently Ignored Because the Query’s WHERE Clause Doesn’t Match It Exactly

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 868 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 561 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com