I enabled a sparse checkout
git init
git remote add <url>
git config --global core.sparseCheckout true
echo "assets" >> .git/info/sparse-checkout
git pull origin master
Git checked out only the assets folder for me
But now, I want to enable full branch checkout again (checkout folders/files), but it doesn't seem to work.
1) first I disabled config
git config --global core.sparseCheckout false
2) removed the entries in .git/info/sparse-checkout
But git didn't checkout any of the other folders/files for me, it seems it is sticking to 'assets' folder.
Could anyone tell me how can I reset/disable this sparse checkout without creating a new repo.?
If you get stuck, run git sparse-checkout disable to return to a full working directory. The init subcommand sets the necessary Git config options and fills the sparse-checkout file with patterns that mean “only match files in the root directory”.
"Sparse checkout" allows populating the working directory sparsely. It uses the skip-worktree bit (see git-update-index[1]) to tell Git whether a file in the working directory is worth looking at. If the skip-worktree bit is set, and the file is not present in the working tree, then its absence is ignored.
Update with git 2.25+ (Q1 2020), as I mentioned in "Git sparse checkout with exclusion", you now have the git sparse-checkout
command.
More precisely, as noted in Tao's answer:
git sparse-checkout disable
Disable the
core.sparseCheckout
config setting, and restore the working directory to include all files.
Leaves the sparse-checkout file intact so a latergit sparse-checkout init
command may return the working directory to the same state.
Original answer: 2016
You can see an example of "undoing" a sparse checkout in this script by Roscoe A. Bartlett:
git read-tree
is important.
echo "Undoing sparse checkout"
# Get the full tree back
echo "*" > $SC_FILE
git config core.sparsecheckout true
git read-tree --reset -u HEAD
# Wipe out all traces of sparse checkout support
rm $SC_FILE
git config core.sparsecheckout false
The article "Adventures in Git - SparseCheckouts" by Rich Somerfield propose a similar option (also valid for submodules):
echo "/*" > .git/info/sparse-checkout
echo "/*" > .git/modules/<MODULEPATH>/info/sparse-checkout
git read-tree -mu HEAD
git config core.sparseCheckout false
braham-snyder adds in the comments that updating a .git/info/sparse-checkout
(to checkout and track additional files) can be achieved with
git read-tree --dry-run HEAD
While VonC's answer is certainly correct and will help with the imminent problem, I feel the need to elaborate and explain the underlying issue.
Git's sparse-checkout
makes use of the skip-worktree
bit, which basically tells git to consider the file in your working directory to be "up to date", regardless of the true state.
When using sparse-checkout
git will apply this bit to all files which do not match the patterns described in your sparse-checkout
file. When disabling sparse-checkout
, or deleting the pattern file, this bits will still be set and the files won't return. You can read about it here.
As such you have to remove the skip-worktree
bit manually from the files in question. The easiest approach certainly being the suggestions from VonC.
The reasoning behind this is quite simple. The skip-worktree
bit is not exclusively used for sparse-checkout
but it's rather a tool in git's toolkit. Other processes make use of the same bit, or a user might even use it own his own (personally I use it regularly to ignore changes to configuration files when debugging).
On a sidenote: You can actually get a list of the files which have been flagged with the skip-worktree
bit, by using git ls-files -v
. This will list all files under version control; the files with the skip-worktree
bit are prefixed with a S
.
If you only want to list the skip-worktree
flagged files you can easily parse and grep the list with the following command: git ls-files -v | grep '^S' | cut -d' ' -f2
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With