Perhaps you have already encountered this file in some git repo. It simply tells git to skip specific files or folders. Like you probably wouldn't want to maually exclude the node_modules folder before each commit, you can just include it in this file. Let's try it!
Remember the best practices project starter template? It also has a .gitignore file as do probably most of the projects that use git. It's a minimal one, but it does importantly include the "node_modules" folder:
So as you see it's as simple as just adding the name of the folder or file to the .gitignore file and that's it. Git will automatically recognize it and ensure that these files get skipped.
You have to actually push the .gitignore file to the repo, so that others working with your project don't have to create one.
It's very useful to read on how the authors behind the Pro Git book explain ignoring files.
It's also very useful to check out the .gitignore templates that the community has come up with. Available here and of course, to explore the internet for more best practices.
Create a new folder anywhere, then run
git init to initialize a new repo.
Then just add a new text file. The content is not important.
Then just add the full name of the text file to your .gitignore and you will notice that after saving the files, no changes show up in your Git tab!
Here is a great article on .gitignore by Atlassian.