Live data from Hacker News

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

adamj.eu

61–70 of 101 posts

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

#61
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…

It makes the behavior more obvious from simply looking at the file, for one thing, and it means you can just lump it into your next `git add -A` without needing to handle it specially.

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

#62

Earlier quoted context omitted.

I play around with ComfyUI on my computer to make silly images. To manually install it, you must clone the repo. Then you have to download models into the right place. Where's the right place? Well, there's an empty directory called models. They go in there. IMO that's an effective use of gitkeep.

It's not. echo >repo/models/README.md "this is the directory you place models in" Is infinitely better.

It could be better sure. In fact I think they use a file called PUT_MODELS_HERE not gitkeep

https://github.com/Comfy-Org/ComfyUI/blob/master/models/diff...

But in any case, that instruction was already in the readme as well.

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

#63

Not sure why you can’t just have your build script create the build directory?

Usually, you can. But occasionally you get mildly defective tools that require some directory to exist, even though it's empty. It's easier to add a gitkeep than fix them.

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

#64

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.

Yeah... I don't think you were wrong. Having 100 tiny gitignores makes finding out why something is excluded annoying. Our policy is one root level gitgnore and gitkeeps where required. Some devs will just open the first gitignore they see and throw stuff into it. No thank you.

I share your view. .keep and .gitignore are different things. Having one .gitignore caputuring everything is less mental load.

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

#65
Oh, man, I'd forgotten about these negated .gitignore patterns entirely. It actually hadn't occurred to me that they could override the behaviour of ignoring empty directories.

This is potentially actually useful for me, because I have a project with test data that consists of miniature filesystem sub-trees — that should include empty directories to ensure edge cases are covered. I've been zipping them up and having the test harness unpack them in the test environment, but that's an unnecessary extra point of failure (and it stuffs undiffable binary files into the commit history).

Edit: Ah, no, if this doesn't work from the project-global .gitignore (specifying a folder to keep, even though it's empty and doesn't even have its own .gitignore) then it doesn't solve the problem. :(

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

#66

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.

Yeah... I don't think you were wrong. Having 100 tiny gitignores makes finding out why something is excluded annoying. Our policy is one root level gitgnore and gitkeeps where required. Some devs will just open the first gitignore they see and throw stuff into it. No thank you.

I like to make a .local folder at the top of the project, which contains a .gitignore that ignores everything. Then I can effortlessly stash my development notes there without affecting the project .gitignore or messing around within the .git directory.

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

#67
My preference is to use the build system to create built artifacts, and I consider the build/ directory to be a built artifact. Wrangling Git into doing the first fundamental build step is off, in my opinion.

However, if you disagree, my favorite "Git keep" filename is "README.md". Why is this otherwise empty directory here, how does it fit into my source tree, how is it populated, and so forth.

One of my pet peeves with the latest AI wave is the time we spend creating files to help AI coding agents, but don't give the same consideration to the humans who have to maintain and update our code.

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

#68

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.

Yeah... I don't think you were wrong. Having 100 tiny gitignores makes finding out why something is excluded annoying. Our policy is one root level gitgnore and gitkeeps where required. Some devs will just open the first gitignore they see and throw stuff into it. No thank you.

> Having 100 tiny gitignores makes finding out why something is excluded annoying. Our policy is one root level gitgnore and gitkeeps where required.

This is not a complicated or important enough problem to justify a team-wide policy. Let it work itself out naturally.

https://git-scm.com/docs/git-check-ignore makes it trivial to debug repo-wide gitignore behavior.

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

#69
post #7

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

Truly, what purpose does this serve? Defining a hierarchy without using is injecting immediate debt. Just introduce it when stuff goes there! If you really insist then at least put something in the folder. It doesn't take much effort to make the change at least a tiny bit meaningful. Better yet just do the work. If you want make a commit in a branch that's destined to be squashed or something, sure, but keep it away…

[deleted]

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

#70
post #54

Earlier quoted context omitted.

I don't know that I like this approach. It certainly works, but it's not specifically what (people expect) a .gitignore file to be used for. That confusion isn't good: https://thecodelesscode.com/case/222 and https://thecodelesscode.com/case/223

.gitignore is the officially recommended way to do this: https://archive.kernel.org/oldwiki/git.wiki.kernel.org/index...

Granted, naming is hard. Routinely using a file named .deleteme or .rememberwalkthedog because it's recommended instead of a more readable solution, is not a compelling reason to switch.
Post reply on HN