1

I have a directory called docs inside my repo. I want this directory to stay on the remote repo as it contains some documentation but is not useful locally. Is there a way I can do something such that this directory will get ignore during cloning? Because I don't want users to clone the docs folder since it contains some large and unnecessary files

So far what I've tried is add it to .gitignore but it doesn't even show up in git status. I've also looked into sparse checkout but not sure if that's gonna solve this problem. I'm a beginner when it comes to git. Is doing something like this even possible? If not, is there an alternate solution to this?

user662650
  • 176
  • 1
  • 12
  • 1
    `.gitignore` is only for untracked files, it won't work for tracked files. There are ways to not checkout certain directories, but they have to download all the files anyway. You can't do it for them, your users have to know to do it manually. Best thing to do is to either use [GIt Large File Storage](https://www.atlassian.com/git/tutorials/git-lfs) for the large files, reduce the size of your documentation directory (for example: only commit the Markdown, don't commit the formatted HTML), or move the docs to a different repo. – Schwern Oct 14 '22 at 18:10
  • There is a new feature called "partial clone" that can avoid downloading some files from the server, but I don't think it's ready for most users yet. Using partial clone can make Git operations extremely slow and painful in some cases. – torek Oct 14 '22 at 21:03

1 Answers1

1

You can use a sparse checkout with exclusion

git clone --filter=blob:none --no-checkout https://github.com/my/repository
cd repository
git sparse-checkout set /* !/folder/to/exclude/
git sparse-checkout init

That way, you should not see the one folder you do not want.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250