Earlier quoted context omitted.
This still confuses me. Do you mean to say "use the .gitignore functionality, and check in the .gitkeep file"?
No. Use a .gitignore instead of .gitkeep. Instead of checking in build/.gitkeep, check in build/.gitignore.
Don't create .gitkeep files, use .gitignore instead (2023)
31–40 of 101 posts
Re: Don't create .gitkeep files, use .gitignore instead (2023)
#32Re: Don't create .gitkeep files, use .gitignore instead (2023)
#33Another example is where you want an empty directory mounted in Docker. If the directory is not there it is created with root permissions and then I can't even look into it.
Re: Don't create .gitkeep files, use .gitignore instead (2023)
#34I'd use `.gitkeep` (or an empty `.gitignore`) if I needed to commit an otherwise-empty hierarchy. But if I'm going to have a `.gitignore` in there anyway, it's not empty.
> The directory is now “tracked” with a single, standard file that will work even after renames.
Does `.gitkeep` not work after renames? Or `.gitignore`?
So I am missing something. :)
Re: Don't create .gitkeep files, use .gitignore instead (2023)
#35The author is misusing .gitkeep. I use it to keep source code folders that don’t contain any code yet, but whose structure is already defined.
Re: Don't create .gitkeep files, use .gitignore instead (2023)
#36The author makes a very common mistake of not reading the very first line of the documentation for .gitignore. A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the NOTES below for details. You should never be putting "!.gitignore" in .gitignore. Just do `echo "*" > .gitignore; git add -f .gitignore`. Once a file is tracked any changes…
Re: Don't create .gitkeep files, use .gitignore instead (2023)
#37It's not that hard to update a .gitignore file every now and then.
Re: Don't create .gitkeep files, use .gitignore instead (2023)
#38Re: Don't create .gitkeep files, use .gitignore instead (2023)
#39What am I missing about this use case? It seems like you should just create `build/.gitignore` with `*` in it and `add -f` it and be done. I'd use `.gitkeep` (or an empty `.gitignore`) if I needed to commit an otherwise-empty hierarchy. But if I'm going to have a `.gitignore` in there anyway, it's not empty. > The directory is now “tracked” with a single, standard file that will work even after renames. Does `.gitkee…
If you rely on `add -f` you will forget to commit something important.
For example, for a tree sitter grammar I developed a couple years ago, here is my .gitignore:
```
# Ignore everything
*
# Top-level whitelist
CHANGELOG.md
# Allow git to see inside subdirectories
!*/
# Whitelist the grammar and tests
!/grammar/*.js
!/test/corpus/*.txt
# Whitelist any grammar and tests in subdirectories
!/grammar/**/*.js
!/test/corpus/**/*.txt
```*