henrykodev
henrykodev

Reputation: 3084

Git Sparse Checkout Leaves No Entry on Working Directory

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:

  1. cd E:\Temp\SomeProjectRepo
  2. git remote add origin https://bitbucket.org/blah/blah
  3. git init
  4. git config core.sparsecheckout true
  5. echo MyProject > .git/info/sparse-checkout
  6. 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"?

Upvotes: 21

Views: 35545

Answers (5)

Tc Blaize
Tc Blaize

Reputation: 61

In my case, the specific folder I was trying to pull didn't yet exist in the repository. So I had to do a push that included the folder ('dist' folder from a built NuxtJS project), then the error was gone and sparse-checkout worked as expected.

Upvotes: 1

w5l
w5l

Reputation: 5746

Solution for Windows users

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.

Powershell

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

Background

See the longer explanation here On Windows git: “error: Sparse checkout leaves no entry on the working directory”

Upvotes: 6

Justin Grote
Justin Grote

Reputation: 137

Windows Git 2.25 Note

2.25 includes the git sparse-checkout feature to frontend some of this work. However, as far as i can tell it writes to the sparse-checkout file as UTF8, which is the same problem noted by Willem

I used the powershell solution in this thread to force ascii https://stackoverflow.com/a/55158885/12927399

Just providing a gotcha warning for git sparse-checkout command!

Upvotes: 2

arfa
arfa

Reputation: 99

if you are working on windows the same as me

you shouldn't get the quotes in the sparse-checkout file, and it will not work and need to use /* at the end of the path

this works for me

echo src/* >> .git/info/sparse-checkout

Upvotes: 3

henrykodev
henrykodev

Reputation: 3084

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).

Upvotes: 33

Related Questions