Generating a .gitignore fileJonathan Bowman Created: August 01, 2020 Updated: July 04, 2023 [Dev] #git
Here is a simple but usable .gitignore file:
*.py[cod] __pycache__ / / .tox/ .coverage .coverage.* .mypy_cache/ node_modules *.sublime-workspace *.sublime-project.vscode *.code-workspace .idea *.swp *~ .DS_Store
This is simply a list of files, or rather a list of file patterns that should be excluded from version control. The file is named
.gitignore and I usually place just one in the root of my project directory.
The patterns themselves can get rather complex. One can learn from the docs, of course. It is worth a look, at the least.
Thankfully, however, a few resources exist to more easily guide the generation of
🔗GitHub starter examples
GitHub provides numerous examples to get you started, available in the github/gitignore repo. You may select your language and build from there.
The online generator gitignore.io provides a place to select the desired languages and editors, and have a custom
.gitignore built for you.
If you know your team well, you can select the editors you know they use, along with the language/platform the project uses. This offers peace of mind, knowing you are not hindering your fellow devs, or spawning needless Emacs vs Vim wars.
🔗gig, a cli for gitignore.io
To install gig, first install go (your package manager may call it golang), then install gig:
gig list will show you all templates available.
gig search allows you to search if
fzf is installed.
Then, pass in a series of templates to use, and your
.gitignore will be printed:
🔗Customize and trim the
Once you have a
.gitignore, take a look if there are lines that are irrelevant, given the tools you use. For instance, if you are using Python but not Mypy, you can eliminate the
.mypy_cache/ line. If you are using Node but not Grunt, you can eliminate the
While removing extraneous lines is not truly necessary, a simpler file is usually an easier file to maintain.
Once you have a
.gitignore you like, you will very likely simply copy it into new projects. But it is nice to know there are tools available when you need them.
Back to top