95 points•faithraven•8 days ago•65 comments•

65 comments

ktm5j7 days ago
Just a nit-pick, but some/repo/path/.gitignore isn't necessarily 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't do something like `git add .` without committing it.

Also `~/.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't want to commit.

Quick edit: I'm not sure `~/.gitignore` works out of the box.. looks like I stuck that in my `~/.gitconfig` for excludesfile

infogulch7 days ago
I've been using $REPO/.scratch/ and .scratch/.gitignore with just `*` in it as a place for coding agents to use as temp storage (scripts, exports, plans, etc) that won't get committed. It's much easier to access these files under the repo path instead of wading through /tmp.
crtasm7 days ago
Out of the box you can use ~/.config/git/ignore and ~/.config/git/config
ktm5j7 days ago
I have no ~/.config/git directory, ~/.config/git/config might take higher precedence, but ~/.gitconfig works too.
nom7 days ago
you can add .gitignore to .gitignore ;)
ktm5j7 days ago
True! But a gotcha there is that if your repo does have a .gitignore in the tree then this trick won'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 ./` will stage changes to any file in the commit tree, even if that file matches a line in gitignore.
spider-mario7 days ago
In fact tup does exactly that to the .gitignores it generates.
sinabis7 days ago
yes, that works perfectly
moritzwarhier7 days ago
Wait until you learn about

  .git/exclude
  --assume-unchanged
  --no-update-index
.

And fwiw, I think global/home-dir .gitignore is bad, for everything except of OS-level spam like .DS-Store

happymellon7 days ago
Nah, I generate dependency trees from gradle because of the crappy way current $job has aggressive transient dependency scanning and I can't stand just updating someone else's transient dependency without validating that there isn't at least a new version of whatever pulled it in.

I have dependency_tree globally excluded because it is my unique naming convention. Actually it might just be my unique approach because other people don't seem to mind having 1000 overrides for libraries they don't use.

6LLvveMx2koXfwn7 days ago
This is great, and nicely written up in the context of agentic repos etc, but presumably no-one reads the official docs, right: https://git-scm.com/docs/gitignore where the multiple ways of ignoring files are clearly stated?
faithraven7 days ago
Until Claude suggested .git/info/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't, and I suspect most people don't either. Especially with git, which nearly everyone learns by doing; very few of us ever sit down and learn it properly. That's why I wrote it up: so a few more people can learn this the way we learn everything else in git, by accident.

Now that you mention it, I should add a link to those docs in the article. Thanks!

onaclov20007 days 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.
alexpotato7 days ago
There is a tweet doing numbers on Twitter right now which is effectively:

"Do the reading b/c you would be amazed how many people don't do the reading"

windward7 days ago
Do the reading b/c there's a machine that has done all the reading so it's hard to add value if you maintain the anti-intellectualism of 2010s software dev.
bigfishrunning7 days ago
So many people treat git commands like magic words, and then are terrified when they mess up their repo (example in this xkcd... https://xkcd.com/1597/)

Reading documentation is a superpower

BeetleB7 days ago
For a lot of tools, people usually read the docs once, and obscure stuff is quickly forgotten.
stephbook7 days ago
I have never seen these two files in any git repository I've cloned so far.
fortran777 days ago
That’s because, unlike .gitignore, they are not committed.
psygn897 days 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't allow extending and that's where this would come in handy. Anyone have any tricks for that?
faithraven7 days ago
You might be surprised, it's sort of possible. Ask your favourite AI agent about git clean filters, and .git/info/attributes, the per-clone sibling of .git/info/exclude. The docs are here: https://git-scm.com/docs/gitattributes#_filter
jo-m7 days ago
You can from the checked in config file include a local file which is not checked in (only if it exists).

For example, with direnv, the `.envrc` in my projects usually has

    source_env_if_exists .envrc.local
And the repo also ships with a `.envrc.local.example` file.
BeetleB7 days ago
You missed this:

> Some configs don't allow extending

BigTTYGothGF7 days ago
> but pushing the silly filename I picked for my private notes to a remote repository feels unclean

Pick a directory for them and ignore the directory. Other team members who want to keep their own notes can use that directory as well.

Read the full thread on Hacker News →

Related stories