.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
~/.gitignoreabout, 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:
- sources compiled/transpiled into intermediary code files (e.g.
.oin C/C++ universe), distribution packages, other deliverables, logs etc. whatever derives from tracked source code.
- dev environment temporary files and/or e.g. IDE settings specific to the project (yet very specific to a particular IDE)
- 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
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 (
Project contributors may also agree on that scratches and notes are stored under
tmp/ and should not be shared via git remote.
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:
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.
.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:
- Add a rule to exclude your favourite yet not hypy IDE to project's
- 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.
- Create a
.gitignorefile in your home directory
- Populate it with exclusion rules you would have in any project (dev environment and IDE settings, subdirectories for notes and scratches etc.)
git config --global core.excludesfile ~/.gitignore
You are done! Share your discovery with colleagues.
Cover image credits: timbercode.pl