Currently, whenever I create a file that I’d like Git to track I simply add it to the index. If I don’t add it to the index Git would not “see it”. So why should I use a .gitignore file, as opposed to just not adding it to the index?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ll generally find that adding each and every file one by one can become tedious when your project becomes bigger.
In Java, you may end up with many
.classfiles that you wouldn’t want to add to your repository. Similarly, you may end up with many.ofiles in C, or.pycin Python (for example).Having patterns like
*.class,*.o,*.pycin your.gitignorefiles allows you to ignore those files once and for all. Subsequentgit statusruns (or similar if you’re using a GUI) will not tell you these are new, untracked files, thereby letting you focus on the files that are really new and noticeably untracked.This can also be useful if you add an entire directory (e.g.
git add myproject): this lets you ignore a category of files altogether.