by Git performs a great job of noticing when new files are added to the working directory or when current files that are in the repository are modified in our working directory, but that’s not always desirable.

If we create a file and put it in the root of our repository (the root of the project) called .gitignore, Git will read this file and use its rules when looking at the other files to make a decision on what should be tracked and what shouldn’t.

The simplest thing is just to put a simple name of the file and that file would get ignored, but we can also use pattern matching, basically simple regular expressions like an asterisk, question mark, character sets like: So, for example, if we want to ignore all files in the logs file directory that end in .txt, we can do that with logs/*.txt.

We can also put comments in the gitignore file by just putting a # sign in front of any text that we want it to be a comment in the gitignore file, maybe we want to provide the reason why we ignored something and any blank lines are simply going to be skipped.

Related Articles