brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: core.excludesFile gives git a global ignore list for every repository

Git
~/tips/tip-git-core-excludesfile-global-ignore

git config --global core.excludesFile ~/.gitignore_global

Ignores files like .DS_Store in every repository from one personal file.

Putting .DS_Store or editor swap files into the .gitignore of every project is silly, since they come from my machine and not from the project. A global ignore file keeps them out of all repositories in one go.

git config --global core.excludesFile ~/.gitignore_global
printf '.DS_Store\n*.swp\n.idea/\n' >> ~/.gitignore_global

The file uses the same patterns as a normal .gitignore. Git reads it for every repository you use, next to the project’s own ignore rules.

You may not even need the setting. The manual says the default is $XDG_CONFIG_HOME/git/ignore, or $HOME/.config/git/ignore when that variable is not set, so a file at ~/.config/git/ignore is picked up automatically.

When a file is ignored and you wonder why, git check-ignore -v <file> prints the rule and the file it comes from.

Caveats: this is personal, so a rule your teammates need still belongs in the project’s .gitignore. A file that git already tracks stays tracked, because ignore rules only apply to untracked files. And a path in the config is not expanded in every case, so if the file is not picked up, check with git config --get core.excludesFile that the value is what you expect.

Further reading: git config, core.excludesFile (Git documentation)

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link