16 comments

  • ktm5j59 minutes ago
    Just a nit-pick, but some&#x2F;repo&#x2F;path&#x2F;.gitignore isn&#x27;t <i>necessarily</i> committed to the repo. For example, if your repo has no .gitignore file, you can totally add one in your clone without adding it to the tree. Of course then you can&#x27;t do something like `git add .` without committing it.<p>Also `~&#x2F;.gitignore` works as a global gitignore. I usually stick something like `katie*` in there so I can copy some `script.sh` to `katie_script.sh` and then I can make changes that I don&#x27;t want to commit.<p>Quick edit: I&#x27;m not sure `~&#x2F;.gitignore` works out of the box.. looks like I stuck that in my `~&#x2F;.gitconfig` for excludesfile
    • crtasm50 minutes ago
      Out of the box you can use ~&#x2F;.config&#x2F;git&#x2F;ignore and ~&#x2F;.config&#x2F;git&#x2F;config
      • ktm5j36 minutes ago
        I have no ~&#x2F;.config&#x2F;git directory, ~&#x2F;.config&#x2F;git&#x2F;config might take higher precedence, but ~&#x2F;.gitconfig works too.
        • crtasm23 minutes ago
          Yes you may have to create the directory :)
    • infogulch29 minutes ago
      I&#x27;ve been using $REPO&#x2F;.scratch&#x2F; and .scratch&#x2F;.gitignore with just `*` in it as a place for coding agents to use as temp storage (scripts, exports, plans, etc) that won&#x27;t get committed. It&#x27;s much easier to access these files under the repo path instead of wading through &#x2F;tmp.
    • nom53 minutes ago
      you can add .gitignore to .gitignore ;)
      • ktm5j23 minutes ago
        True! <i>But</i> a gotcha there is that if your repo does have a .gitignore in the tree then this trick won&#x27;t work. I had a coworker try to do just that and we were all pretty confused when his changes kept getting committed. `git add .&#x2F;` will stage changes to any file in the commit tree, even if that file matches a line in gitignore.
      • spider-mario17 minutes ago
        In fact tup does exactly that to the .gitignores it generates.
  • havnagiggle15 minutes ago
    I prefer a presubmit check for DO NOT SUBMIT and also disable Git smart commits. And then I have those floating around as needed. Seems to avoid all the foot guns I&#x27;m reading about, and makes it obvious and easy for other people to use as well. I guess it still shows in my diff tree, but &#x2F;shrug I still prefer seeing them.
    • etatester10 minutes ago
      What footguns? I disable most git hooks so your solution still has ways to shoot your feet.
  • 6LLvveMx2koXfwn1 hour ago
    This is great, and nicely written up in the context of agentic repos etc, but presumably no-one reads the official docs, right: <a href="https:&#x2F;&#x2F;git-scm.com&#x2F;docs&#x2F;gitignore" rel="nofollow">https:&#x2F;&#x2F;git-scm.com&#x2F;docs&#x2F;gitignore</a> where the multiple ways of ignoring files are clearly stated?
    • faithraven1 hour ago
      Until Claude suggested .git&#x2F;info&#x2F;exclude, it never crossed my mind to question how ignoring worked. A search would have answered it in seconds, but you have to think to ask first. I didn&#x27;t, and I suspect most people don&#x27;t either. Especially with git, which nearly everyone learns by doing; very few of us ever sit down and learn it properly. That&#x27;s why I wrote it up: so a few more people can learn this the way we learn everything else in git, by accident.<p>Now that you mention it, I should add a link to those docs in the article. Thanks!
      • onaclov20001 hour ago
        This is true, using AI to help discover better ways of working with stuff is pretty epic, reading docs are about as exciting as writing docs, esp when you are trying to get something done.
    • alexpotato1 hour ago
      There is a tweet doing numbers on Twitter right now which is effectively:<p>&quot;Do the reading b&#x2F;c you would be amazed how many people don&#x27;t do the reading&quot;
      • bigfishrunning1 hour ago
        So many people treat git commands like magic words, and then are terrified when they mess up their repo (example in this xkcd... <a href="https:&#x2F;&#x2F;xkcd.com&#x2F;1597&#x2F;" rel="nofollow">https:&#x2F;&#x2F;xkcd.com&#x2F;1597&#x2F;</a>)<p>Reading documentation is a superpower
        • coldpie5 minutes ago
          I&#x27;m definitely the friend in the alt-text of this comic. What do you mean you haven&#x27;t read gitcore-tutorial(7)??
        • faithraven1 hour ago
          I&#x27;d wager a small sum that git is the tool most of us learned by accident, some of them fortunate, some less so. Thankfully, this one was the former.
    • stephbook1 hour ago
      I have never seen these two files in any git repository I&#x27;ve cloned so far.
      • fortran771 hour ago
        That’s because, unlike .gitignore, they are not committed.
  • n4bz0r3 minutes ago
    I absolutely despise when people commit their personal ignore patterns into .gitignore. My opinion is that the code in the repository shouldn&#x27;t know anything about personal environments. The exception is when the <i>entire</i> team benefits from having their common ignore patterns in the repo - in this scenario, the environment details are no longer personal and it doesn&#x27;t make much sense to not commit them. In any other situation, people are perfectly capable of ignoring their crap on their own.
  • markbnj21 minutes ago
    Very useful. Minor typo in the post if you&#x27;re adding the claude code flag: it&#x27;s &quot;respectGitIgnore&quot; not &quot;respectGitignore&quot;.
    • faithraven19 minutes ago
      Thanks, but I think it&#x27;s the other way round. The docs, the published JSON schema and the binary itself all spell it respectGitignore, lowercase i, named after the .gitignore file. <a href="https:&#x2F;&#x2F;code.claude.com&#x2F;docs&#x2F;en&#x2F;settings-reference#respectgitignore" rel="nofollow">https:&#x2F;&#x2F;code.claude.com&#x2F;docs&#x2F;en&#x2F;settings-reference#respectgi...</a>
  • psygn891 hour ago
    This is great... one thing I wish is to be able to exclude are lines, for instance some lines in my config that only benefits the work I do. Some configs don&#x27;t allow extending and that&#x27;s where this would come in handy. Anyone have any tricks for that?
    • faithraven1 hour ago
      You might be surprised, it&#x27;s sort of possible. Ask your favourite AI agent about git clean filters, and .git&#x2F;info&#x2F;attributes, the per-clone sibling of .git&#x2F;info&#x2F;exclude. The docs are here: <a href="https:&#x2F;&#x2F;git-scm.com&#x2F;docs&#x2F;gitattributes#_filter" rel="nofollow">https:&#x2F;&#x2F;git-scm.com&#x2F;docs&#x2F;gitattributes#_filter</a>
    • jo-m1 hour ago
      You can from the checked in config file include a local file which is not checked in (only if it exists).<p>For example, with direnv, the `.envrc` in my projects usually has<p><pre><code> source_env_if_exists .envrc.local </code></pre> And the repo also ships with a `.envrc.local.example` file.
  • henrydoughty44 minutes ago
    On Windows I never found ~&#x2F;.config&#x2F;git&#x2F;ignore. I just used .gitignore for everything.<p>I&#x27;ve been leaving notes sitting untracked rather than put a filename only I use into the repo. .git&#x2F;info&#x2F;exclude is what I actually needed.
  • dpkirchner1 hour ago
    See also: git check-ignore<p>You can use this subcommand to learn which ignore file is causing your files to be ignored.<p><a href="https:&#x2F;&#x2F;git-scm.com&#x2F;docs&#x2F;git-check-ignore" rel="nofollow">https:&#x2F;&#x2F;git-scm.com&#x2F;docs&#x2F;git-check-ignore</a>
    • faithraven48 minutes ago
      That&#x27;s a great shout. With more than one ignore file in play, this command is gold.
  • grimgrin49 minutes ago
    this was probably discovered by many when seeking how to globally ignore agent configs, until perhaps they decided they&#x27;d like to start committing agent configs. though that&#x27;s just a `git add -f`
  • biglyburrito2 hours ago
    I&#x27;d never heard of <i>.git&#x2F;info&#x2F;exclude</i>, <i>core.excludesFile</i>, or <i>~&#x2F;.config&#x2F;git&#x2F;ignore</i> before. Thanks for posting this!
  • festive-minsky3 hours ago
    Thanks I had no idea about these either!
  • globular-toast1 hour ago
    Magit really is the only git frontend worth using. It exposes all of this kind of stuff in an easy to use way. You can easily ignore files using all three methods with magit.<p>The more useful thing here is the &quot;typical use&quot; of each one. People who don&#x27;t know about other methods get this wrong a lot and put cruft from their own tools&#x2F;editors in .gitignore which is annoying.
  • DamonHD3 hours ago
    Ah, very good!
  • ivyBadger9201 hour ago
    [dead]
  • cxr54 minutes ago
    I&#x27;ve never seen a .gitignore that was justified, ever. It probably shouldn&#x27;t even exist. I&#x27;ve run into projects often enough with horked build scripts or bad docs about build pre-requisites, where upon failing partway through and necessitating some fix, the build failure leaves the tree in a state where it <i>still</i> won&#x27;t build successfully even after fixing the thing that caused the original failure. The only fast fix is to rm .gitignore, then look at the output of git-status and rm -rf all the crap that it shows the original build attempt splattered everywhere before re-running the build script for a third attempt. Thanks, .gitignore.<p>.gitignore is banished in every project I&#x27;m in charge of. Everyone is required to manage their personal .git&#x2F;info&#x2F;exclude themselves, and any changeset attempting to slip .gitignore into the project will get ipso facto rejected. (Anyone is free to submit a change that adds a file contrib&#x2F;gitignore if you think you have a set of useful globs relevant to the project that will be a help to others, along with instructions to cp that file to .git&#x2F;info&#x2F;exclude, but .gitignore is not making it in.)<p>Git needs to ship a git-ignore command (or extend git-config) that exclusively works by managing .git&#x2F;info&#x2F;exclude for you, including converting &quot;legacy&quot; .gitignore into the less anti-social version.
    • quietbritishjim37 minutes ago
      Or, you could have a build system that does a 100% out-of-tree build into .&#x2F;build, and then if the build is broken you delete that one directory. You hardly need git to help you with that.
      • cxr31 minutes ago
        Oh, I can? Cool advice! How do I get the people with bad hygiene that we&#x27;re talking about to follow it?<p>(You have lost the plot; your response amounts to explaining how soap and water works to someone who has just described their office mate&#x27;s tendency not to shower.)
        • quietbritishjim15 minutes ago
          Get a new job? You can&#x27;t be that &quot;in charge of&quot; a repo if you can&#x27;t enforce rules this basic. In fact, I don&#x27;t understand how you can enforce something as (being polite) unusual as banning .gitignore and yet can&#x27;t enforce build system hygiene.
    • athorax26 minutes ago
      This is one of the strangest opinions I&#x27;ve seen in awhile. Your complaint seems like it should be pointed at projects not having a working &quot;clean&quot; make target.<p>Also:<p><pre><code> git status --ignored git clean -ndX # preview what would be removed git clean -fdX # actually delete the files (warning: destructive)</code></pre>
    • Phemist28 minutes ago
      So all your fellow devs do `ln -s contrib&#x2F;gitignore .&#x2F;git&#x2F;info&#x2F;exclude`?<p>Also you can do `git status --ignored` and it will list all files changed, even if ignored. If that is really your main issue.