4

I've seen people adding .gitkeep, .keep files in empty directories on a Git repo and I just don't see why I would ever need to track en empty dir.

Can you mention some examples where that would be necessary?

Related

What are the differences between .gitignore and .gitkeep?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
pgpb.padilla
  • 2,318
  • 2
  • 20
  • 44
  • One possible reason might be because the directory _won't_ be empty in a main (or other) branch. This could eliminate some confusion. – Tim Biegeleisen Mar 16 '16 at 00:55
  • Git does not remove empty folders when you switch branches, in those cases there's no need to add a `.gitkeep` or `.keep` file. I am trying to understand why would you keep an directory purposely empty in the repo. – pgpb.padilla Mar 16 '16 at 16:08

4 Answers4

7

When creating a template project for others to implement it may be convenient to include empty directories to help guide where certain content should go.

For example, an MVC template repo could include empty model, view, and controller folders that are already in the correct location and ready to be filled with files.

Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
  • In my experience this use of empty folders has never worked, people will end up adding files wherever they feel like. In such cases you have to move the misplaced files to the right place anyway so there's no use in trying to preempt other devs by creating empty folders, the right directories can be created when needed, not before. – pgpb.padilla Mar 16 '16 at 16:05
4

Example: When your app does not have privileges to create new directories in the server it has been deployed.

Source: Is it possible to make git to track empty folders?

Community
  • 1
  • 1
pgpb.padilla
  • 2,318
  • 2
  • 20
  • 44
1

I usually add a .gitkeep file in directories that must exists for my app to run properly (I avoid having to write code that checks their existence and their creation). For example, the directory that holds user avatars.

  • So you are deploying your git repo straight into the execution environment? I would have assumed that most projects would involve a packaging stage, and an installation stage, either of which could set up necessary run-time folders. – Jolta Oct 31 '17 at 11:47
  • 1
    This is only for small applications, like a blog or something. The point is to get going as soon as possible, if your app requires a packaging stage than you should definitely go the extra mile to check the existence of required directories. –  Oct 31 '17 at 11:52
0

Sometimes, a empty folder need to to be kept for files generated when compiling.

gzh
  • 3,507
  • 2
  • 19
  • 23
  • 2
    I would say that a folder which is a build artifact should _not_ be versioned under Git, except if perhaps there is a weird permissions issue. – Tim Biegeleisen Mar 16 '16 at 01:08
  • @TimBiegeleisen, If it is permissions issue about creating folder, maybe It has failed when run `git clone` – gzh Mar 16 '16 at 01:56
  • I don't think it's necessary to track build products. It is fair to assume that if you're building a product then you already have enough privileges to create files so creating a folder should not be an issue. – pgpb.padilla Mar 16 '16 at 16:01