Live data from Hacker News

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

adamj.eu

51–60 of 101 posts

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

#52

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…

I think I'd prefer to have all ignores and un-ignores explicitly in the file and not have some of them defined implicitly because a file was added to tracking at some point.

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

#53

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

There may be other directories. I think it's useful to be able to see the entire directory structure of a repo when you check it out, and not just after running some scripts.

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

#54
post #29

Earlier quoted context omitted.

No. Use a .gitignore instead of .gitkeep. Instead of checking in build/.gitkeep, check in build/.gitignore.

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

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

#56

.gitkeep is intuitive and easy to understand. Unignoring a .gitignore is not intuitive. This falls squarely into "clever optimization tricks that obscure intent and readability". Don't do things like this. It's not that hard to update a .gitignore file every now and then.

Then put a comment in the .gitignore.

Using the actual tools built in to git directly removes steps in the process, which is always a good thing, it's documented as part of the git documentation, so you don't have to create a wiki page explaining why there is a ".gitkeep" file that git doesn't recognize itself.

Saying "It's not that hard..." is fine for projects with a few contributors but does not scale.

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

#57

Earlier quoted context omitted.

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…

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.

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

#58

Earlier quoted context omitted.

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…

> Truly, what purpose does this serve? The simplest answer is that sometimes other existing software that I need to use treats an empty directory (or, hopefully, a directory containing just an irrelevant file like .gitkeep) differently from an absent directory, and I want that software to behave in the first way instead of the second. A more thorough answer would be: Filesystems can represent empty directories, so a…

Legitimately asking, please share the name of software that expects/requires an empty directory and interprets .gitkeep in this way, but chokes on a README file.

Many filesystems cannot represent empty directories. Many archive formats also do not. I don't think this a problem in practice. I find this argument extremely weak.

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

#59

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.

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

#60
post #50

Earlier quoted context omitted.

qemu: mkdir build; cd build; ../configure, some projects are like that

Why can’t the configure script do this?

You can. But this makes intent clear. If you clone a git repo and see build/ with only a gitkeep, you are safe to bet your life savings on that being the compiled assets dir.
Post reply on HN