Do You Ignore Your .Gitignore?
I have come to find that a lot of people are confused about .gitignore. Let’s talk a bit about what the file does, how to interact with it, and how to know if it’s not ignoring files like it should.
What it is
.Gitignore intentionally leaves files untracked in git. This is a very useful and important feature. When you are working in a team setting, you don’t want to overwrite each others files. Those are the files that are specific to your computer, so each one should be unique.
How it looks in git
It should look as if git has no idea your file is there—except for when you actually look in your gitignore file. If anything that is in your gitignore file is ever being tracked by git, you have a problem.
One thing to be aware of
Git will not ignore a file that has already been tracked. In order to ignore a file that has already been tracked, the file must become untracked. To do this you can use git rm --cached filename
It can remember
A great way to save time and energy is to utilize global gitignore. You can set up your computer to always ignore certain files, be it a specific file type or your API keys.
The usual suspects
For example, here is what your .gitignore file might look like when working with wordpress.
Github has a useful resource with popular .gitignore templates. Check it out here.