What should you put in your Gitignore File?

The .gitignore file is where you tell Git which files you don’t want to push from your local repository to your remote repository — for performance and especially security reasons.

This makes the .gitignore file one of the most important things to do when you create a new git repository unless your project doesn’t contain any private or sensitive data.

Here is a list of things you should generally put in your .gitignore file:

  • API keys: any file containing security concerns, such as environment variables .env should not be pushed remotely.
  • node_modules: there’s no reason to push the source code for your projects’ dependencies, it’s a waste of time and bandwidth.

You can create your .gitignore file manually by running this command inside your project directory:

touch .gitignore

And then add the files you want to ignore, for example:

# Dependency directories

# Logs

# API keys

Auto-generate .gitignore file in VSCode

To auto-generate the recommended default settings for .gitignore files, you can use a plugin such as VSCode’s gitignore by CodeZombie.

After installing the gitignore plugin in VSCode, do the following:

  • Open VSCode’s Command Palette: CMD + Shift + P (Mac), CTRL + Shift + P (Windows)
  • Type gitignore and select Add gitignore either by hitting enter or by clicking with your mouse
  • Now type “node” until you see Node.gitignore, and hit enter.

Video demonstration:

In a second or so you’ll have a .gitignore template file in your project directory, with the recommended defaults.

Chances are that you’ll want to keep most if not all of these defaults, as well as adding your own specific configurations to it along the way.

Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊


Share & Discuss on