Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Sparse Checkout Leaves No Entry on Working Directory

Tags:

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

like image 231
henrykodev Avatar asked Jul 11 '14 06:07

henrykodev


People also ask

How does Git sparse checkout work?

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

What is sparse checkout path?

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


2 Answers

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

like image 126
henrykodev Avatar answered Sep 17 '22 17:09

henrykodev


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”

like image 36
Willem Avatar answered Sep 16 '22 17:09

Willem