Live data from Hacker News

Don't create .gitkeep files, use .gitignore instead (2023)

adamj.eu

41–50 of 101 posts

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#41

Earlier quoted context omitted.

It's especially funny since my answer is wrong anyway! The other top answer is much better. I did get a lot of early SO brownie points from that one answer though.

[dead]

Well, Claude is here making .gitkeep files like nobody's business.

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#42

The 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…

This is functionally the same. What do you mean by “you should never”? According to who?

What an arrogant take. This is preference. Don’t mistake it for correctness.

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#43
post #16

The 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…

Yeah, this. Plus a mistake from the article: $ echo '*\n!.gitignore' > build/.gitignore The \n won't be interpreted specially by echo unless it gets the -e option. Personally if I need a build directory I just have it mkdir itself in my Makefile and rm -rf it in `make clean`. With the article's scheme this would cause `git status` noise that a `/build/` line in a root .gitignore wouldn't. I'm not really sure there's…

> The \n won't be interpreted specially by echo unless it gets the -e option.

Author's probably using Zsh, which interprets them by default.

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#44

The 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…

The point of that line is to robustly survive a rename of the directory which won't be automatically tracked without that line. You have to read between the lines to see this: they complain about this problem with .gitkeep files.

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#47
post #39
post #34

What 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…

That's a hack. What you should do is a .gitignore with * and then a whitelist of paths like src/**/*. 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/*.j…

> If you rely on `add -f` you will forget to commit something important.

But isn't the idea in TFA to blacklist the entire `build/` tree? We don't want to add anything there.

Re: Don't create .gitkeep files, use .gitignore instead (2023)

#48

I'm not sure if I'm the one to blame for this or not, but the earliest reference to ".gitkeep" I can find online is my 2010 answer on Stack Overflow: https://stackoverflow.com/a/4250082/28422 If this is all my fault, I'm sorry.

This Rails commit from May 2010 mentions gitkeeps and it's a few months older than your SO post, so it seems you're absolved from guilt:

https://github.com/rails/rails/commit/785493ffed41abcca0686b...

Post reply on HN