# Bug: Checkout in sparse mode can overwrite uncommited files

1 messages from 2026-06-19 to 2026-06-19. Participants: charmocc.
Thread: https://gitlist.dev/t/65842

## charmocc, 2026-06-19 16:31

Subject: Bug: Checkout in sparse mode can overwrite uncommited files
Message-ID: <15FXjc8hV3WTRkSg1-PMUqlEFqWxJ5iw5qVbO9WoMX0NEyB4l1AOGSOhtBsxZbgTYGjzZfLJoFr9cyaL9_5Jazwa1OQGPzS7_MCTnkfUJvQ=@proton.me>

```

Hey. Today I discovered inconsistent behavior in sparse mode that may lead to data loss during initial checkout. Please have a look.

What did you do before the bug happened? (Steps to reproduce your issue)

$ git init foo
$ cd foo
$ echo 1 > file
$ git add file
$ git commit -m 'test'
$ cd ..

$ git clone --no-checkout foo bar
$ cd bar
$ echo 2 > file
$ git checkout
error: The following untracked working tree files would be overwritten by checkout:
	file
Please move or remove them before you switch branches.
Aborting
$ cat file
2
$ git sparse-checkout set
$ git checkout
warning: The following paths were already present and thus not updated despite sparse patterns:
	file

After fixing the above paths, you may want to run `git sparse-checkout reapply`.
Your branch is up to date with 'origin/master'.
$ cat file
1

What did you expect to happen? (Expected behavior)

Checkout should fail due to uncommited changes

What happened instead? (Actual behavior)

After enabling sparse mode checkout overwrites file in working directory

What's different between what you expected and what actually happened?

In normal mode checkout is aborted correctly but in sparse it overwrites data and gives misleading message

Anything else you want to add:

[System Info]
git version:
git version 2.53.0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
rust: disabled
gettext: enabled
libcurl: 8.18.0
zlib: 1.3.1
SHA-1: SHA1_DC
SHA-256: SHA256_BLK
default-ref-format: files
default-hash: sha1
uname: Linux 7.0.0-22-generic #22-Ubuntu SMP PREEMPT_DYNAMIC Mon May 25 15:54:34 UTC 2026 x86_64
compiler info: gnuc: 15.2
libc info: glibc: 2.43
$SHELL (typically, interactive shell): /bin/bash


[Enabled Hooks]


```
