Gitignore Generator

.gitignore Generator

Pick a language, framework or editor. Combine as many as you like, then copy or download.

0 lines
Copied!

A .gitignore file tells Git which files to leave out of your repository, such as dependency folders, build output and .env files. This free generator lets you pick your languages, frameworks and editors, combines their rules into one file, and lets you copy or download the result. It runs in your browser, so nothing you type is sent anywhere. For a deeper look at how the file works, read our guide to understanding .gitignore.

Table of Contents

How to Use the .gitignore Generator

  1. Search for a language, framework, platform or editor. Try "node", "python", "android" or "vscode".
  2. Click to select. The template appears as a chip and its rules show in the preview right away. Stack as many as you need. Most real projects use two or three, such as a language, a framework and an editor.
  3. Remove anything you do not need by clicking the × on its chip. You can also use the arrow keys, Space and Enter in the list.
  4. Add custom rules in the box if your project needs something the templates do not cover.
  5. Copy or download the result and save it as .gitignore in your project root. If your browser renames the downloaded file, rename it back to .gitignore.

When you select several templates, duplicate rules are removed automatically. Always skim the result before you commit it, because every project is a little different.

Writing Custom Rules

The custom rules box uses normal .gitignore syntax. These are the patterns you will use most:

PatternWhat it does
*.logIgnores every file ending in .log, in any folder.
build/Ignores any folder named build. The trailing slash means folders only.
/build/Ignores only the build folder in the same folder as the .gitignore file.
docs/*.txtIgnores .txt files directly inside docs, but not in its subfolders.
**/tempIgnores anything named temp, at any depth.
!keep.logRe-includes a file that an earlier rule ignored. It cannot re-include a file inside an ignored folder.
# noteA comment. Blank lines are ignored too.

Mistakes That Actually Happen

MistakeFix
Adding a rule after the file is already committedRun git rm --cached filename (add -r for a folder), then commit. .gitignore does not affect files Git already tracks.
Writing build when you mean the folderUse build/, so only folders match and not files with that name.
Using a template from the wrong stackSkim it first. A folder like lib or bin can mean different things in different ecosystems.
Ignoring lock files by accidentMost projects commit package-lock.json, yarn.lock, go.sum and .terraform.lock.hcl, so everyone gets the same versions.
Assuming .gitignore protects a secret that is already committedIt does not. Rotate the credential immediately. See the next section.
Ignoring a folder, then trying to re-include a file inside itGit cannot do this. Ignore the folder's contents instead, for example .vscode/* followed by !.vscode/extensions.json.

The secret mistake is the only one on this list that can really cost you. The others just make your repository messier.

If You Already Committed a Secret

Adding a file to .gitignore does not erase it from history. Git keeps every past version of every file, so the key is still in an old commit whether or not you track the file from now on. Treat the credential as burned: revoke it and create a new one. To remove it from the history too, a tool such as BFG Repo-Cleaner or git filter-repo can strip it, but that rewrites commit hashes for everyone on the project, so coordinate with your team first. Anyone who already cloned or forked the repository may still have the old copy, which is why rotating the credential matters most.

If you are not sure what else is buried in your history after a force-push or a rebase, our Git undo guide covers recovery for most of the things people panic about.

Frequently Asked Questions

Why is my .gitignore not working?

Most often, the file was already committed before you added the rule. Run git check-ignore -v filename to see which rule matches. If it prints nothing for a file Git is already tracking, add --no-index to the command. Then use git rm --cached to stop tracking the file.

Should I commit the .gitignore file itself?

Yes. Sharing it keeps everyone's setup consistent. Otherwise each person builds their own version, and you lose the point of having one.

Can one .gitignore cover multiple languages in the same repo?

Yes. Put all the rules in one file, and Git applies whichever match. This is the main reason to stack templates in the generator above, instead of writing each ecosystem's rules from memory.

Is there a global .gitignore for OS or editor files?

Yes, and it is worth setting up once. Run git config --global core.excludesfile followed by the path of a file on your machine. Personal files like .DS_Store or editor settings then stay out of every repo, and your project .gitignore can focus on the project itself.

Does .gitignore slow Git down?

Not in any way you will notice. Git does not scan the contents of ignored folders, so ignoring a large dependency folder like node_modules can actually make commands such as git status faster.

Post a Comment