2024-12-16
Local-only gitignore
Red passenger traffic light in Munich. Taken while doing some street photography with flipez.
tl;dr: Enable a local-only untracked gitignore file for all repos using the config option core.excludeFiles
.
Gitignore is a great way of excluding unwanted files from a git repository. Usually you want to track it within the repo and add all the coverage, binary or test files that get produced during the build process.
This is fine as long as you want to track all unwanted files in each git repo. Everyone uses vim, so ignoring swap files is fine, too. But there are a bunch of individual tools and editors that place files in the repo which need to be added over and over again by each individual for each repo.
Git has support for a global gitignore file that gets applied in each repo without tracking it in each one: config.excludeFiles
Motivation
Recently I started to use rbenv
for managing my ruby installations. Setting a ruby version in the current repository
creates a file .ruby-version
. I don’t want to add this file to any existing ruby repo just because I’m using it while other colleagues don’t.
Usage
Create an individual gitignore file outside of any repo , e.g. in your home dir:
.ruby-version
Then just add it to the local git config (usually ~/.gitconfig
):
> git config --global core.excludeFiles=<path to your gitignore>
+hf