.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:
- 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. - 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 .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:
- Add a rule to exclude your favourite yet not hypy IDE to project's
.gitignore
- 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
- Create a
.gitignore
file in your home directory~/
(C:\Users\your-user-name\
under Windows). - Populate it with exclusion rules you would have in any project (dev environment and IDE settings, subdirectories for notes and scratches etc.)
- run
git config --global core.excludesfile ~/.gitignore
You are done! Share your discovery with colleagues.
Cover image credits: timbercode.pl
Top comments (2)
Look for
.git/info/exclude
too. It is good for project specific ignore list.Thank you for your comment.
Would add smth just for consistency:
project specific and yet individual.