Skip to content
snowkitDev

A .gitignore for Node.js

Start from a Node.js .gitignore with .env files, VS Code, macOS and Windows already included, add anything else your project uses, and download the file.

Build a .gitignore

Pick everything your project uses. Press Enter in the search to add the first match.

added at the end
.gitignore

            

Duplicate rules are kept only once

The rules are merged into a single file with a heading for each part, and anything listed twice is kept only once. Pick your languages, tools and editors, add your own rules, and copy a ready-to-use .gitignore. It is free and runs in your browser.

How to make a .gitignore

  1. Use Search templates to find your language, framework, editor or operating system, and tick each one that applies.
  2. Add anything special under Your own rules.
  3. Read the combined .gitignore and press Copy, or Clear to start over.
  4. Save it as a file named .gitignore in the top folder of your project.

Where the rules come from

The templates follow the widely used community lists for each language and tool, trimmed of rarely needed lines. Build output, dependency folders, caches, logs, editor settings and operating system clutter such as .DS_Store and Thumbs.db are covered, and lines starting with ! keep files you usually want, like the Gradle wrapper or shared VS Code settings.

Keep secrets out of Git

Add Environment files and secrets to ignore .env files, private keys and credential files while keeping .env.example. A .gitignore only stops new files from being added. If a secret was already committed, remove it with git rm --cached, then rotate the key, because it stays in the history.

Using the file

Save it as .gitignore in the top folder of your repository, next to the .git folder. Patterns ending in / match folders, a leading / anchors a pattern to the repository root, ** matches any depth, and later rules win over earlier ones. Run git status --ignored to check what is being skipped.

Tips

  • Make the .gitignore before the first commit. It is much harder to clean up afterwards.
  • Ignore generated files, such as build folders and dependency folders, not your source code.
  • Commit a .env.example so others know which settings are needed. The env example generator can make one.
  • If a file is already tracked, adding it to .gitignore will not untrack it. Use git rm --cached first.

Who uses it

Developers starting a project, students submitting code, and freelancers handing a repository to a client. Sections are included for many languages, editors and operating systems.

Questions

Where does the .gitignore file go?

In the top folder of your repository, next to the .git folder.

Why is a file still tracked?

Ignore rules do not affect files that are already tracked. Remove them from tracking with git rm --cached.

Is anything uploaded?

No. The file is built in your browser.

Where to next

Carry on with what you just made, still on your device.

More from Snowkit