What is the best practice for empty folders in the.gitignore

Some people told me that the correct thing is to create an empty file and put it inside each folder and set a .gitignore like this:

/pasta/subpasta/*
!/pasta/subpasta/.arquivovazio

And other people told me to create a file .gitignore inside each folder with the following contents:

# ignorar todos
*
# exceto o .gitignore
!.gitignore

Create a single file .gitignore or one in each folder? What is the best alternative?

Remembering that both forms were tested and worked.

Author: Maniero, 2016-05-09

2 answers

Depends on what you want to do:

  • If you want the folders to be versioned, even empty, create them and put an empty .gitkeep file in them;

  • If you don't need to version the folders (but don't want to commit them in case they are created), just add the folder path in the .gitignore file in the project root.

 1
Author: Rodrigo Rigotti, 2016-05-17 18:03:06

Look guys, I researched, analyzed and came to the conclusion that each situation is unique and for me the best was to create a file .gitignore inside each folder I want to keep empty and set to the .gitignore ignore all files except it. Because I have folders that are empty but I also have folders that are occupied by files that I do not want to version, such as test images of sites, so for me, the best thing was to create a file .gitignore inside each folder that I want to leave versioned and empty. Thank you for everyone's help.

 1
Author: Alexandro Zaleski, 2016-05-17 18:21:07