Best practice for empty folders in . gitignore

Asked

Viewed 961 times

4

Some people told me that the correct thing is to create an empty file and put inside each folder and set one .gitignore thus:

/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 the two forms were tested and worked.

  • I think the answer potentially borders on the question of personal opinions. My answer is one, so I put it as a comment and not as an answer. I’d rather create a single file and keep keeping to it than keep creating a file for every folder I create. Decreases the amount of files that both Git and I have to keep paying attention to.

  • Nice, I found that point of view interesting.. But here’s the question, what’s the difference between creating an empty file in each folder or putting a gitignore? changes something pro git? because doing the way you said I would need to create an empty file equal in each folder, otherwise it does not versiona..

  • 1

    I never thought about it, but I also never had to create a project with empty directories. I do not see the need, perhaps because I have never had this requirement. If I really needed directories that won’t contain anything, I would let the application create them as needed and at the time of use, but wouldn’t keep directories in the repository.

  • 1

    Yes, I agree with you but in my case today I have some websites that need, for example in some use Smarty and it generates the files within templates_c and I have no way to create it through the application, so I need to have it in version control.. and there are some providers, for example the kinghost that won’t let me create folders, give them permissions through php, so I need to have the image folders that the client registers in the empty version control for not Versing test images for example

  • One possible solution would be to use a . gitpeak file in empty directories. question of the OS will help you understand better.

  • I don’t know gitpeak, I’ll take a look.. Thanks for the tip

  • If your application is php, put an index.php instead of a hidden file or something like that. This way you add a simple layer of security to your application.

Show 2 more comments

2 answers

2

Depends on what you want to do:

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

  • If you don’t need to select folders (but don’t want to commit them if they are created), just add the folder path to the file .gitignore at the root of the project.

  • beauty.. you and the second one who tells me about . gitkeep, I’ll try to implement.. Thank you

1

Look, guys, I did some research, some analysis, and I came to the conclusion that each situation is unique and for my best was to create a file. gitignore within each folder I want to keep empty and set to . 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 don’t want to see, like images of testing websites, so for me, the best thing was to create a file. gitignore inside each folder I want to leave versioned and empty. Thanks for all your help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.