Live data from Hacker News

.gitignore Isn't the only way to ignore files in Git

nelson.cloud

161–170 of 188 posts

Re: .gitignore Isn't the only way to ignore files in Git

#161

The global/user wide exclude is a feature that should be more widely known. I frequently have people submitting changes to add their IDE/OS/AI/... files to every project's .gitignore. They are almost always pleasantly surprised when I tell them that they can add them to their standard configuration and have them ignored everywhere without bothering every project and without risk of accidentally committing them on a p…

I'd rather have a pristine repo (no .ds_store/.idea/etc) than a pristine .gitignore file.

Re: .gitignore Isn't the only way to ignore files in Git

#162

Fun article, but it leaves out my favorite "almost ignore" feature in Git: `.gitattributes`. This file lets you specify that git should "ignore" the diff from certain files. For instance, Node projects have a `package-lock.json` that is pure noise from a Git standpoint (it's just massive amounts of diff specifying specific versions of libraries, and the real human-readable version is in a separate `package.json` file…

Sounds like a powerful feature for subverting code review…

Re: .gitignore Isn't the only way to ignore files in Git

#163
post #11
post #7

Earlier quoted context omitted.

Interested in examples of the types of scripts others collaborators wouldn't be able to use? Like scripts for PR workflows?

Usually when I'm working in one part of the codebase and I have sample data or something at a specific path on my local machine and Im testing the same thing over and over again will I make a Makefile or something and info/exclude it to help me keep focused. That's one way I use it.

I use git worktrees pretty heavily in my own workflows (I worked like an AI agent before AI agents made worktrees cool). I like to track my ephemera/utility scripts in git, so what I do is keep a private ephemera repo for those, and then use `git worktree add` from the collaborative repo to check out the branch I'm working on there into a subdirectory of my ephemera repo.

  git-home/
    company-project/ 
This way, too, I can easily use the same ephemera scripts across multiple branches, or even multiple repos, concurrently.

Re: .gitignore Isn't the only way to ignore files in Git

#164

Fun article, but it leaves out my favorite "almost ignore" feature in Git: `.gitattributes`. This file lets you specify that git should "ignore" the diff from certain files. For instance, Node projects have a `package-lock.json` that is pure noise from a Git standpoint (it's just massive amounts of diff specifying specific versions of libraries, and the real human-readable version is in a separate `package.json` file…

You should 100% track package-lock.json, and I'll go a step further and say you should most likely track node_modules too.

Re: .gitignore Isn't the only way to ignore files in Git

#165
post #8

~/.config/git/ignore and ~/.config/git/config is the proper place for your global git config and ignore instead of creating a ~/.gitignore_global and changing the config. IMO. my dotfiles are a lot smaller at the root level taking advantage of the ~/.config/ for a lot more things. the git exclude isn't used as much because it doesn't get committed to the repository so you'd have to recreate it each time you wanted to…

As a bonus, you can (should?) version control your `~/.config` dir to enable future revisions and sharing.

check out gnu stow for this! i place my config files in ~/dots, mirroring the structure as if it were my home directory, and gnu stow can symlink everything to my home directory for me. then, only the dots directory is checked into version control.

i find this better than putting all of ~/.config in git, since i don't necessarily want everything there to be version controlled.

video i learned this from: https://youtu.be/y6XCebnB9gs

gnu stow: https://www.gnu.org/software/stow/

Re: .gitignore Isn't the only way to ignore files in Git

#166
post #161

The global/user wide exclude is a feature that should be more widely known. I frequently have people submitting changes to add their IDE/OS/AI/... files to every project's .gitignore. They are almost always pleasantly surprised when I tell them that they can add them to their standard configuration and have them ignored everywhere without bothering every project and without risk of accidentally committing them on a p…

I'd rather have a pristine repo (no .ds_store/.idea/etc) than a pristine .gitignore file.

Well you still ignore those things, just not with a committed .gitignore. Now your repo and your gitignore are pristine

Re: .gitignore Isn't the only way to ignore files in Git

#167
post #107
post #91

Earlier quoted context omitted.

> you just want to see that the file changed I check the diff for uv.lock (Python counterpart of package-lock.json) every time I merge a PR. It is important to know which direct or transient dependencies have been updated. We don't blindly bump all dependencies to the latest versions (you shouldn't either).

Python packages aren't quite so insane on transitive dependencies. The diff of package-lock.json can be novel length.

write your requirement.txt files via

    pipdeptree --freeze
to see this clearly

Re: .gitignore Isn't the only way to ignore files in Git

#168
post #152

Here's how I use the excludes file to set a different config for a project directory containing multiple repos: https://laszlo.nu/blog/project-level-git-config.html

I *literally* cannot read that yellow text on the white background. I even tried changing the brightness to almost 0, but there is just not enough contrast.

Oh no, I forgot to test light mode. Thanks for letting me know!

I'll fix it as soon as I'm in front of a computer. Happy Midsummer!

Re: .gitignore Isn't the only way to ignore files in Git

#169
post #140

I have a habit of writing myself notes in various .txt files, and then not cleaning them up often enough so they end up cluttering my `git status` view. I ended up with a solution not mentioned in the article: create a `scratch` directory, and a `scratch/.gitignore` file containing just one line: `*`. This makes Git ignore everything in the scratch directory, including that same .gitignore file — so I never accidenta…

There's also the global gitignore configuration (core.excludesfile=~/.gitignore_global), which for me contains things like: *.swp, .DS_Store, scratch, etc.

Re: .gitignore Isn't the only way to ignore files in Git

#170

Fun article, but it leaves out my favorite "almost ignore" feature in Git: `.gitattributes`. This file lets you specify that git should "ignore" the diff from certain files. For instance, Node projects have a `package-lock.json` that is pure noise from a Git standpoint (it's just massive amounts of diff specifying specific versions of libraries, and the real human-readable version is in a separate `package.json` file…

People are jumping on it being an important file to review. You don't want to ignore the diff. Even if that's true, you definitely do not want to attempt merge two lock files, and using the .gitattributes file to set the merge strategy is a good idea!

There are also "semantic" diff and merge tools for a variety of languages, and a few specialized for JSON. That stuff was always pretty niche, but it's becoming more popular with AI agents and not wanting to or not being able to review every merge by hand.
Post reply on HN