.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
- API keys: any file containing security concerns, such as environment variables
.envshould 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:
And then add the files you want to ignore, for example:
# Dependency directories
# API keys
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.