4

I find out there are many ways that people have been trying to commit a temporary directory. Should there be a standardized one? If yes, which one would it be? (it would be better to hear your justification too)

Here are a list of possible solution to track your directory in git:

  • commit .gitdirectory file. IMHO, it is more intuitive to use the word directory which refers to committed directory.
  • commit .gitkeep file. Unfortunately this is not documented as mentioned in the answer. But people have seems to agreed upon this to be the standard. I couldn't find any particular reason why this is more acceptable compared to .gitdirectory intuitively. (perhaps for some historical reason from other SVC tools to enforce .keepme file.
  • commit .gitignore file. This is by far official documented solution of committing an empty directory. Unfortunately there's a discussion going on .gitignore vs .gitkeep.

    some people see this as confusing since the goal is to keep the empty directories, not ignore them;

  • commit README file. Anyway you have to write what this directory is for, and what files will be put there in the future. (It also solve the documentation problem too)

My philosophy is to keep things clean with what the majority of the community accept as the best practices or conventions of doing certain things.
How you would add an empty folder with Git?

Community
  • 1
  • 1
Yeo
  • 11,416
  • 6
  • 63
  • 90

2 Answers2

3

Your question illustrates the "Standardize & acceptable" way to commit an empty directory in git:

Put a placeholder in that (otherwise) empty folder.

What that placeholder is don't really matter, as long as it provide the service you want (which is here to commit the empty folder).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

For a directory that needs to stay empty, I recommend a .gitignore file which looks like this:

# This directory must always exist, but stay empty for various important reasons.
*
!.gitignore

This is great for a build artifacts directory, ensuring that cloners have it, but don't accidentally commit files within it.

lutzky
  • 598
  • 5
  • 12