Please, do not pollute project's .gitignore
Tags: git, versioncontrol
Published: 2018-11-08 20:08:46

---
title: Please, do not pollute project's .gitignore
published: true
description: Project .gitignore may grow reflecting contributor's individual preferences. Not really good. Yet can be easily avoided.
tags: git, versioncontrol
cover_image: https://static.timbercode.pl/images/covers/gitignore-2-sztuczki.png
---

`.gitignore` is a rule-set defining resources we do not want to be git tracked, or putting it other way be ignored by git.

> **Spoiler alert.** If you know what is `~/.gitignore` about, you don't need to read any further.

There are 3 most common major groups of resources that we do not want or just do not need to track with git:
1. sources compiled/transpiled into intermediary code files (e.g. `.obj` or `.o` in C/C++ universe), distribution packages, other deliverables, logs etc. whatever derives from tracked source code.
2. dev environment temporary files and/or e.g. IDE settings specific to the project (yet very specific to a particular IDE)
3. scratches, notes, clipboards etc.

You don't need to track derivatives from item 1 since you can build deliverables at any time from sources and having those under VCS control is senseless. So these exclusions are pretty helpful and every project contributor would benefit from having them listed in project's `.gitignore`.

Next you will add your favourite IDE temps to `.gitignore`, your colleagues will add theirs, and someone else may wonder one day if `.DS_store/` is anything to do with project's database or why idea sharing is not encouraged on the project (`.idea/`).

Project contributors may also agree on that scratches and notes are stored under `tmp/` and should not be shared via git remote.

OK.

There are many collections and helpful resources that would assist you in compiling a `.gitignore` that covers your technology stack (item 1), most common IDEs (item 2), and also smth like `tmp/` to cover item 3.

To name a few:
 - https://github.com/github/gitignore
 - https://www.gitignore.io/
 - https://github.com/CodeZombieCH/vscode-gitignore
 - https://www.npmjs.com/package/gitignorer

But why do you want to have even a hint of anything not related to the project in your project files? IDEs come and go. Personal notes? Too personal.

Project `.gitignore` becomes polluted. Rules to cover item 1 are OK as those **bring** value to the project contribution team.

Imagine (really easy do) you contribute to an open source project where `.gitignore` doesn't list your fav IDE exclusion rule. There are two options to resolve the situation:
1. Add a rule to exclude your favourite yet not hypy IDE to project's `.gitignore`
2. Do something like `git add -A && git reset -- MyLovelyIDE/*` at every commit

Both are neither good, nor convenient.


There is a proper place to keep your individual preferences out of git track and not confusing your project mates.

**Global `.gitignore`**

1. Create a `.gitignore` file in your home directory `~/` (`C:\Users\your-user-name\` under Windows).
2. Populate it with exclusion rules you would have in any project (dev environment and IDE settings, subdirectories for notes and scratches etc.)
3. run `git config --global core.excludesfile ~/.gitignore`

You are done! Share your discovery with colleagues.


---
Cover image credits: [timbercode.pl](https://timbercode.pl/blog/2017/02/19/gitignore-2-sztuczki/)