What is the best practice for empty folders in .gitignore

3

Some people have 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 .gitignore file inside each folder with the following content:

# 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 have been tested and worked.

    
asked by anonymous 09.05.2016 / 20:42

2 answers

1

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

    
17.05.2016 / 20:21
0

It 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 do not need to version the folders (but do not want to commit them if they are to be created), just add the folder path in the .gitignore file in the project root.

17.05.2016 / 20:03