Let's initialize a Git repository here. You can see that I have a TypeScript project set up over here. In the package.json, I've added TypeScript types dependency.
If we check our Git status, you can see that node modules is being tracked by our Git repository, which is not what we desire. Gitignore files solve this exact problem by letting us ignore the exact files and folders that we desire not to be included in our git repository.
Let's add a gitignore file. If you head to the Git tab, you can see a bunch of files that are being tracked from the node modules folder. If we add node modules into our gitignore file, and wait for the changes to reflect, you can see that all the files and folders from the node modules folders are now not being tracked by the tracking system.
Creating gitignore files is daunting, and basically, it should always be automated. I'll show you a couple of ways you can do this.
If you go to your GitHub account and make a new repository, let's name this test. If you come down, you can see a add.gitignore button. If you press this, it will give you a list of options to choose from. Let's say, "Add project as a node project."
I'll type in node, and you can see that we have a node option here. Select it and create a repository. Once a repository is created, you have .gitignore file over here. If you open it up, all the files and folders set up for you. You can copy it and paste it in your project.
This is a bit lengthier process. The shorter way is to use tools provided by the ID. Let's head back to Visual Studio code. Let's go to the extensions, and search for gitignore. You can see that we have an extension that does this. It's called as the gitignore extension.
I already have it installed. You can go ahead and install it. If you open up the command panel and search for the command add gitignore, you'll be given a list of options from which you can choose.
I'll again type in node to add a node.gitignore. It will ask me to append or overwrite. I'll append it to our existing gitignore file. If we go ahead and open our gitignore file, you can see that new files and folders have been added to gitignore.
Though all of these ways are good, the most recommended way is to use gitignore.io. Suppose you're making a node project with angular, and you're using Visual Studio as an ID. I'll write in node, and then angular, and for the ID, I'll write in Visual Studio.
As I press create, it will generate me the gitignore file that I can simply copy and paste into my project.