-1

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.

Pascal
  • 11
  • 3
  • 1
    If you use a Terminal window and a shell (bash, zsh, etc), does everything show up as expected? That's generally the way to work with Git anyway, but the Finder *should* be picking up on checkouts. – torek May 17 '22 at 19:37
  • @torek The terminal doesn't show the files either. (I honestly don't like working with the terminal too much, I do it when I have to. For accessing, creating or moving files around on my computer I simply use the Finder. And for git I use Sourcetree instead of the terminal. That's why I didn't mention the terminal in my question.) – Pascal May 17 '22 at 22:58
  • If you're in a Terminal window, in a shell, and you run `git checkout somebranch` and the files don't show up there, then either Git itself isn't working at all (seems unlikely) or the files just are not in the commit you've selected to check out. But either way that rules out a problem with the Finder. I have used Git on my own mac with no such problems, though I'm not running a bleeding-edge Git there; in fact, it's quite old at 2.20.1 (I should update it). – torek May 17 '22 at 23:36
  • I see you mention sparse checkout. I don't use this, especially not with an older Git like 2.20. Using sparse checkout literally tells Git "don't check out anything I didn't specifically tell you that you SHOULD check out" *unless* you use the newfangled "cone mode" stuff that's not in my older mac Git. You're probably best off avoiding sparse checkout here. – torek May 17 '22 at 23:38
  • `git sparse-checkout` doesn't work as I thought it would, my fault. Even when the folders are created locally, the sparse-checkout doesn't automatically update and thus the content of the folders is not accessible. – Pascal May 18 '22 at 10:25
  • Please edit the question to focus and elaborate on the above comment (just delete and replace the current question title and body, focussing on the actual now-understood problem) - otherwise this question will very likely get closed and/or continue to accrue downvotes. – AD7six May 18 '22 at 15:01

1 Answers1

0

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

Pascal
  • 11
  • 3