-1

I've been searching for how to create a folder in a git repository. Everyone says you can't do it.

But a lot of the authors of programming books I read have a git reposiory for their book and organize it into folders for each chapter with the Visual Studio solution file and project folders in each chapter folder. Sometimes the chapter folder has two folders; Beginning and End and in each of those folders are the solution file and project folders for the beginning and end of the chapter.

How can I set this up in Git and get chapter folders up their for a book I am writing.

The following is a screenshot of what I am thinking of. It is a screenshot of the repository for Apress publishing's Pro ASP.Net Core 6 book:

enter image description here

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Sam
  • 4,766
  • 11
  • 50
  • 76
  • I'll add 1 to the *can't* set of people. Well, empty folders that is. If you want to organize files into a hierarchy, then you should have no trouble doing that. – Jeff Holt Aug 27 '23 at 00:48
  • 2
    Are you trying to ask how to do it on GitHub? That's covered here: [How do I create a folder in a GitHub repository?](/q/12258399/4518341) – wjandrea Aug 27 '23 at 00:54
  • 2
    Just to be clear, Git and GitHub are not the same thing. I noticed you put the [tag:github] tag but never actually said "GitHub" in the question. – wjandrea Aug 27 '23 at 00:55
  • 2
    You can't have _empty_ directories. Apart from that, everything works as usual – knittl Aug 27 '23 at 08:13
  • 1
    @wjandrea - thank you. I think that is what I am looking for. – Sam Aug 28 '23 at 00:09

1 Answers1

1

No one has ever said "you can't do it". The only thing that is even slightly confusing is that git does not store folders. It stores files. If those files are in folders, git will keep track of the folder structure.

So, in your local repo, just create the folder you want, create files within that folder, and do

git add folder/file1 folder/file2
git commit

That's all there is to it.

You can't add an EMPTY folder to a repo. If you need that, just add an empty .gitignore file to the folder.

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30