I am trying to use sparse-checkout to just check-out a directory from a BitBucket repository, but getting a "Sparse checkout leaves no entry on working directory" error when I try to pull.
The BitBucket repository has the following directory structure:
I have a local directory on E:\Temp\SomeProjectRepo on my Windows 7 laptop. I want to just checkout/pull "MyProject" from the BitBucket repository to my local directory, so I can just work on E:\Temp\SomeProjectRepo\MyProject.
So I created "E:\Temp\SomeProjectRepo" and did the following in DOS:
cd E:\Temp\SomeProjectRepo
git remote add origin https://bitbucket.org/blah/blah
git init
git config core.sparsecheckout true
echo MyProject > .git/info/sparse-checkout
git pull origin master
At step 6, I get the "Sparse checkout leaves no entry on working directory". I have tried different syntax in step 5 (e.g. MyProject\
, SomeProjectRepo\*
, SomeProjectRepo\MyProject\
, etc, etc) but none worked.
How do I use sparse-checkout (or any other tools) to only work on "MyProject
"?
"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.
If A is root directory and sparsing to B sub-directory then Sparse checkout path is: /B/ for B directory. @OK999: Try BackSlash \ before space or any special character in the file or folder name. Example: /Path/To/My Folder will be like /Path/To/My\ Folder or try passing path between quotes "/Path/To/My Folder".
OK, I got this working. As I expected it was not working because of step 5.
The line below works now:
echo "MyProject/*"> .git/info/sparse-checkout
The important thing is to use /
, use *
and leave no space at the end of the directory.
Then you may pull again or checkout the branch (git checkout master
).
On Windows, the echo "..." > outfile
command creates a file in default system encoding. Git cannot deal with that, it requires the file to be in ASCII.
Modify the existing file to become ASCII, assuming you created it already and it doesn't work:
Set-Content .git\info\sparse-checkout "MyProject/*" -Encoding Ascii
Or to create the file with correct encoding from the start:
echo MyProject/* | out-file -Encoding Ascii .git/info/sparse-checkout
See the longer explanation here On Windows git: “error: Sparse checkout leaves no entry on the working directory”
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