0

I am in a strange predicament. The repository that I want to clone is too large so I've been using sparse-checkout to get specific files and folders that I need. Here are the instructions I followed to do this: Is it possible to do a sparse checkout without checking out the whole repository first?.

An example: I was able to checkout Folder 1 and Folder 2 from the repository.

Repository   
--> Folder1
--> Folder2

I now need to save a new folder with files into the repository. What is the best way to do this?

It would have to be structured like this:

    Repository   
    --> Folder1
    --> Folder2
    --> NewFolder
O_O
  • 4,397
  • 18
  • 54
  • 69
  • The standard git workflow should work (`git add`, `git commit`, ...), even for a sparse checkout. Did you try that and run into a problem? – larsks Jan 23 '18 at 21:41
  • I guess the problem I am running into is that I cannot do a sparse checkout because the path to the NewFolder that I want to checkout is non existent. – O_O Jan 23 '18 at 21:52
  • From the instructions I linked above, I tried doing "echo "NewFolder/*" > .git/info/sparse-checkout" and "git checkout master" but it returns "error: Sparse checkout leaves no entry on working directory". – O_O Jan 23 '18 at 21:56
  • `git add`, `git commit`, `git push` works for me in a sparse repo without adding the new dir to `.git/info/sparse-checkout`. – phd Jan 23 '18 at 22:47

1 Answers1

2

I'm moving this to an answer, because I think it will help for me to show you what I am suggesting so that you can tell me if I am not understand you.

The repository that I want to clone is too large so I've been using sparse-checkout to get specific files and folders that I need.

Note that a sparse checkout only partially helps with this issue! Sparse checkout only control what shows up in your work tree; you're still cloning the entire repository.

An example: I was able to checkout Folder 1 and Folder 2 from the repository.

I assume that you mean you have performed a sparse checkout of these two folders:

$ git clone --no-checkout https://git.example.com/myrepository
$ cd myrepository
$ git config core.sparseCheckout true
$ echo -e 'Folder1\nFolder2' > .git/info/sparse-checkout
$ git checkout master

So that your working directory looks like:

$ ls
Folder1 Folder2

You want to create a new folder. You can do that simply by adding and populating the folder:

$ mkdir newfolder
$ echo 'Hello world' > newfolder/newfile
$ git add newfolder
$ git commit -m 'added a new folder'
larsks
  • 277,717
  • 41
  • 399
  • 399
  • Thank you. That really helped. It looks like I am able to commit the folder and files as normal. – O_O Jan 23 '18 at 23:21