Vinyll's blog

( Python, Javascript & Web stuff… )

Using gitignore – the right way

Organize your gitignore file

Some very bad practice is to insert everything you want to be ignore in your project's .gitignore file, like making a generic github file. You can find a lot of these bad practices on the web.

Why is it so bad? Because in a team, noone can be a 100% sure that a line in a gitignore file can be safely removed without impacting some other dev.

How to know if my gitignore file is badly written

If any line in your project's .gitignore file would not concern a new developer coming on the project, then you can improve it!

If reading your gitignore file you cannot guess where that file is supposed to be located and whether it is a file or a folder.

How to write a line in a gitignore?

These simple rule can make it easier to read and avoid name collision

Examples:

Understanding gitignore locations

There are (more than) 3 possible locations where to ignore a file/folder for git:

home gitignore

is located in ~/.gitignore and contains anything that is specific to you like your OS files, your editors files, etc.

Globally anything that will be common to multiple projects in a different language should probably be here.

Project's gitignore

Here you should insert anything that is specific to the nature of your project, like *.pyc for python 2, __pycache__/ for python 3, /node_modules/ for npm projects, …

Project's .git/info/exclude

for ignoring files and folders that are specific to your project and to your preferences or environment. In other words, this location is to common point between your home gitignore and your project's gitignore. It is less common to use this though.

Examples for python: /env/, /venv/

By vinyll on March 15, 2017


Comments