You know, .gitignore are files that tell git which files are excluded from the repo. It's an useful and powerful tool, that made git usage easier. Let's clarify some things : on our git repositories, we don't want any temporary file. That includes compiled files from the techno you used (like
*.o files if you are using C, or the
__pycache__ directory in python), but also files from your OS or your IDE (like
Thumbs.db in Windows or
#*# files on emacs). But files depending on your OS MUST NOT BE in your .gitignore.
Take a look at this gitignore :
It mixes project ignored files (
*.o, due to C or C++ usage) and development environment files (
*~ tmp files and
.idea IDE directory). It's a bad gitignore.
The right way
We have to split the gitignore above into two ones :
#This one will still be in your project directory
#This one will be in your home directory
But it's not magical. Git doesn't know where your global gitignore file is. You have to tell it with this simple command:
git config --global core.excludesfile '~/.gitignore'
# You see, there is no fucking $ in the line above, and you understand it. Magic, isn't it ?
The evil way
Yes, there is an evil way. Not the way I described at the beginning of this article, but a much more evil way. Yes, it's possible. Have you ever heard about gitignore.io ? It's a tool that claims to help you to create gitignores. You simply get them from an api and they are here. You can also retrieve several gitignores from several technos merged into one. But it's not as cool as it looks like.
First, they are using dirty
$ in their bash command lines. Then, let's try some bash commands:
Their tool allow us to merge project ignored files and OS ignored files. That's a big big mistake.
Even worse, it makes duplicates.
curl <https://www.gitignore.io/api/C,C++> 2>&- | wc -l # It prints 68
curl <https://www.gitignore.io/api/C,C++> 2>&- | grep -v '^#' | sort | uniq | wc -l # It prints 25
Yeah, there is a lot of duplicates. I just remove duplicates and commented lines. There is an empty line remaining. That means this gitignore could fit in 24 fucking lines. So why are you giving me 68 ? You have too many bandwidth and you want to waste it ?
Please never use gitignore.io again. Write your own gitignores, one per project plus a global one. If you want to use already done gitignores, please have a look to this repo, it's pretty good.