DEV Community

Cover image for Generating a gitignore file

Generating a gitignore file

bowmanjd profile image Jonathan Bowman ・2 min read

Here is a simple but usable .gitignore file:

# Python

# Node/npm

# Editors
*.sublime-project # unless most use Sublime

# Misc
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.

The online generator 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

To install gig, first install go (your package manager may call it golang), then install gig:

go get
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.

Discussion (0)

Forem Open with the Forem app