gitsparse-checkout

New folders created in a Git repository are shown as empty on disk


I am new to Git and I am having some problems when creating new folders.

I have a sparse-checkout of a repository (as I don't need the whole thing) and I created a new folder with some files in it, but as soon as I switch directory (either via terminal or even simply changing "location" on macOS Finder) and then come back to it, the folders are empty. To make it clear, the folders are still accessible, but the files I created in them are no longer present. This doesn't seem to be related to the state of the new files, meaning that even pushing them to the remote (which works properly, as I can see the newly created folders and files on the GitLab webpage) doesn't resolve the problem.
I did some testing by creating a new repository on GitHub and everything seems to work as expected. I can create new folders and subfolders with some files in them and these remain present even after switching directory.

I really have no idea what the problem could be. I tried to be as thorough as possible, thanks for the help.


Solution

  • git sparse-checkout doesn't "update" automatically when creating new folders in the directory of the repository, meaning that the new folders are shown but their content is not. This is simply how git sparse-checkout works and is not a problem with Git nor with macOS Finder.

    In order to solve this, one should simply tell Git to "include" the new folders in the sparse-checkout. From the terminal move to the directory of the repository and then use git sparse-checkout add <folder_name>. In the case of 1) a new folder then <folder_name> is the name of the folder, 2) a new subfolder inside a new folder then it is enough to set the name of the folder as <folder_name> and both the new folder and its files and the subfolder and its files will be included in the sparse-checkout, 3) a new subfolder in an existing folder then <folder_name> is the path <folder_name/subfolder_name>.