10 comments

  • jkubicek1 hour ago
    I&#x27;m not sure if I&#x27;m the one to blame for this or not, but the earliest reference to &quot;.gitkeep&quot; I can find online is my 2010 answer on Stack Overflow: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;4250082&#x2F;28422" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;4250082&#x2F;28422</a><p>If this is all my fault, I&#x27;m sorry.
    • selridge47 minutes ago
      This is delightful. Accidental load-bearing SO post.
      • jkubicek42 minutes ago
        It&#x27;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.
  • Arrowmaster1 hour ago
    The author makes a very common mistake of not reading the very first line of the documentation for .gitignore.<p><pre><code> 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. </code></pre> You should never be putting &quot;!.gitignore&quot; in .gitignore. Just do `echo &quot;*&quot; &gt; .gitignore; git add -f .gitignore`. Once a file is tracked any changes to it will be tracked without needing to use --force with git add.
    • AgentME1 hour ago
      If you have a project template or a tool that otherwise sets up a project but leaves it in the user&#x27;s hands to create a git repo for it or commit the project into an existing repo, then it would be better for it to create a self-excepting .gitignore file than to have to instruct the user on special git commands to use later.
    • ekipan1 hour ago
      Yeah, this. Plus a mistake from the article:<p><pre><code> $ echo &#x27;*\n!.gitignore&#x27; &gt; build&#x2F;.gitignore </code></pre> The \n won&#x27;t be interpreted specially by echo unless it gets the -e option.<p>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&#x27;s scheme this would cause `git status` noise that a `&#x2F;build&#x2F;` line in a root .gitignore wouldn&#x27;t. I&#x27;m not really sure there&#x27;s a good tradeoff there.
  • cortesoft2 hours ago
    Not sure why you can’t just have your build script create the build directory?
    • andybak2 hours ago
      Because you might not have a build script?
      • drdec10 minutes ago
        Then why do you need a build directory?
        • himata41136 minutes ago
          qemu: mkdir build; cd build; ..&#x2F;configure, some projects are like that
  • yjftsjthsd-h2 hours ago
    I&#x27;m confused. Having a file gitignored doesn&#x27;t stop you from committing it; AFAIK you can just<p><pre><code> touch build&#x2F;.gitkeep git add build&#x2F;.gitkeep git commit build&#x2F;.gitkeep </code></pre> And that&#x27;s it? There&#x27;s no need to exclude anything.
    • williadc2 hours ago
      The idea is that you don&#x27;t want to check-in any builds.
      • yjftsjthsd-h2 hours ago
        Sure, so gitignore build&#x2F; or whatever. But you don&#x27;t need to unignore .gitkeep
        • akerl_1 hour ago
          The idea is that instead of adding a nonsense file, you use the native .gitignore functionality.<p>&quot;.gitkeep&quot; is just a human thing; it would work the same if you called it &quot;.blahblah&quot;.<p>So their pitch is that if you want to explicitly keep the existence of the directory as a committed part of the repo, you&#x27;re better off using the actual .gitignore functionality to check in the .gitignore file but ignore anything else in the directory.<p>I don&#x27;t find it amazingly compelling; .gitkeep isn&#x27;t breaking anything.
          • dwattttt1 hour ago
            This still confuses me. Do you mean to say &quot;use the .gitignore functionality, and check in the .gitkeep file&quot;?
  • 8cvor6j844qw_d61 hour ago
    Is .gitkeep an established convention somewhere? I&#x27;m curious where the name originated.
    • abustamam59 minutes ago
      Seems to originate form this SO post<p><a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;4250082&#x2F;28422" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;4250082&#x2F;28422</a>
  • suralind2 hours ago
    I want to like it, but I pretty much always have a &quot;cleanup&quot; script that just deletes the entire directory and touches a .gitkeep file. Obviously an even better pattern is to not have any .gitkeep files, but sometimes they are just handy.
  • macote2 hours ago
    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.
    • xyzzy_plugh1 hour ago
      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 <i>something</i> in the folder. It doesn&#x27;t take much effort to make the change at least a tiny bit meaningful.<p>Better yet just do the work. If you want make a commit in a branch that&#x27;s destined to be squashed or something, sure, but keep it away from the shared history and certainly remove it when it&#x27;s not needed anymore.
      • abustamam56 minutes ago
        I play around with ComfyUI on my computer to make silly images.<p>To manually install it, you must clone the repo. Then you have to download models into the right place. Where&#x27;s the right place? Well, there&#x27;s an empty directory called models. They go in there.<p>IMO that&#x27;s an effective use of gitkeep.
      • akoboldfrying1 hour ago
        &gt; Truly, what purpose does this serve?<p>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.<p>A more thorough answer would be: Filesystems can represent empty directories, so a technology that supports versioned filesystems should be able to as well. And if that technology can&#x27;t quite support fully versioned filesystems -- perhaps because it was never designed with that goal in mind -- but can nevertheless support them well enough to cover a huge number of use cases that people actually have, then massaging it a bit to handle those rough edges still makes sense.
  • peter-m801 hour ago
    No, thanks