DEV Community

Cover image for Generating a gitignore file
Jonathan Bowman
Jonathan Bowman

Posted on • Edited on • Originally published at bowmanjd.com

1 1

Generating a gitignore file

Here is a simple but usable .gitignore file:

# Python
*.py[cod]
__pycache__
venv/
htmlcov/
.tox/
.coverage
.coverage.*
.mypy_cache/

# Node/npm
node_modules

# Editors
*.sublime-workspace
*.sublime-project # unless most use Sublime
.vscode
*.code-workspace
.idea
*.swp
*~

# Misc
.DS_Store
Enter fullscreen mode Exit fullscreen mode

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 .gitignore files.

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.

gitignore.io

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:

go get github.com/shihanng/gig
Enter fullscreen mode Exit fullscreen mode

Once installed, 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:

gig gen python vim
Enter fullscreen mode Exit fullscreen mode

Customize and trim the .gitignore

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 .grunt line.

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.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay