Git Sparse Checkout Leaves No Entry on Working Directory
Asked Answered
G

5

21

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:

  • SomeProjectRepo
    • JohnsProject
    • MarysProject
    • MyProject

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"?

Graduated answered 11/7, 2014 at 6:23 Comment(2)
I think you should do step 3 and then step 2Mohammedanism
Possible duplicate of On Windows git: “error: Sparse checkout leaves no entry on the working directory”Methanol
G
33

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

Graduated answered 16/7, 2014 at 3:54 Comment(4)
This also solved my problem with Jenkins sparse checkouts. The checkout path in the Jenkins SCM must use forward slashes. i.sstatic.net/VD93V.pngSilkworm
thanks you made my day! :) actually you dont need to echo the fullpath to the subdirectory . you should echo the location excluding the repo url ! lolDieback
Note for windows users: do not use powershell for the echo command. Use git bash instead. See duplicate answser: #23289506Exarch
The * was the missing puzzle tile that did the trick for me after many times tryingYearround
A
6

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”

Amazed answered 14/3, 2019 at 9:23 Comment(0)
F
3

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

Fasto answered 4/11, 2019 at 5:13 Comment(0)
S
2

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://mcmap.net/q/597890/-git-sparse-checkout-leaves-no-entry-on-working-directory

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

Sheepshank answered 1/4, 2020 at 16:39 Comment(0)
U
1

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.

Urethrectomy answered 13/9, 2022 at 15:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.