1

When I clone a repository on Windows, it complains about a file name with colon, so checkout fails. I want to use sparse checkout to exclude the whole directory, but it doesn't work. Is sparse checkout the correct way to help here?

My steps:

git init <project_name>
cd <project_name>
git remote add origin http://<url>.git
git config core.sparsecheckout true
echo "folder1" >> .git/info/sparse-checkout 
echo "folder2" >> .git/info/sparse-checkout // exclude folder3 as it causes trouble.
git pull origin master

However it still downloads everything and checkout to master fails because of that file with a colon in its name. Am I doing everying correctly and is sparse checkout the correct way to help me?

janw
  • 8,758
  • 11
  • 40
  • 62
codewarrior
  • 723
  • 7
  • 22
  • 1
    `core.sparsecheckout` is not a valid configuration attribute, this is `core.sparseCheckout`, have a look at [this](https://stackoverflow.com/a/13738951/10155936) – Saurabh P Bhandari Dec 17 '19 at 01:44
  • Does this answer your question? [How do I clone a subdirectory only of a Git repository?](https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository) – Saurabh P Bhandari Dec 17 '19 at 01:54
  • Seems I find the root cause, in Windows should not include double quotes when use echo command, removing the double quotes and use exclamation make whole things work. – codewarrior Dec 17 '19 at 23:30

1 Answers1

0

I found the root cause: I should not include double quotes when calling echo, and using the exclamation mark can make the whole thing easier if only few folders need to be excluded.

Here is my script:

@echo off
if "%1"=="" goto blank

git init %1
cd %1
git remote add origin http://<url>.git
git config core.sparseCheckout true
(
  echo /*
  echo !/<dir needs to be excluded>
) > .git/info/sparse-checkout
git pull origin master
echo repo created in %1.
goto :EOF

:blank
echo Please specify a folder name.
janw
  • 8,758
  • 11
  • 40
  • 62
codewarrior
  • 723
  • 7
  • 22