Skip to content
ohsudo, Home

.gitignore & .dockerignore Generator

Ignore files for your stack, in one click.

● Runs 100% in your browser — nothing you type leaves this page.

Every project
Operating systems
Editors
Languages
Infrastructure as code
# Generated by OhSudo — https://ohsudo.com/tools/gitignore-generator/
# Secrets (.env, private keys)
# Commit a .env.example with the variable names, never the real values.
.env
.env.*
!.env.example
*.pem
# Logs and temp files
*.log
logs/
*.tmp
# macOS
.DS_Store
._*
.AppleDouble
.LSOverride
# Windows
Thumbs.db
ehthumbs.db
[Dd]esktop.ini
$RECYCLE.BIN/
# VS Code
# Shared project settings stay in git; personal ones don’t.
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/
# Node.js
node_modules/
dist/
build/
coverage/
.npm/
.eslintcache
*.tsbuildinfo
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

Use it

$ git check-ignore -v node_modules/express/index.js
$ git rm -r --cached node_modules
$ git status --ignored

Both files go in the root of the repo (.dockerignore: next to the Dockerfile, in the build context). Files git already tracks stay tracked until you git rm --cached them.

The address bar updates as you go, so you can bookmark or share the result.

How to use it

  1. Click what your project uses: languages, the editors and operating systems on your team, Terraform or Ansible.
  2. Switch between the .gitignore and .dockerignore tabs — they are generated together, for the same stack.
  3. Save both in the root of the repo. The link keeps your choice, so you can share it with the team.

What you get

Every stack is checked automatically: the .gitignore with git check-ignore, and the .dockerignore with a real docker build, for each stack alone and all of them together.

Common commands

Terminal window
git check-ignore -v path/to/file # which line ignores this file (no output = not ignored)
git status --ignored # see what is being ignored
git rm -r --cached node_modules # stop tracking a folder git already tracks, keep it on disk
git ls-files -ci --exclude-standard # tracked files that your .gitignore says should be ignored
docker build --progress=plain -t myapp . 2>&1 | grep "transferring context" # build context size

Warning

Ignoring a file doesn’t remove it from history. If a .env or a key was ever committed, it is still in every clone. Rotate the secret first, then remove the file with git rm --cached — and, if needed, from history with a tool like git filter-repo.

FAQ

I added a pattern, but git still shows the file. Why?

.gitignore only affects files git doesn’t track yet. A file that was committed stays tracked. Run git rm --cached <file> (or -r for a folder), commit, and from then on it’s ignored. git check-ignore -v <file> tells you which line matches, if any. The other causes — patterns that don’t match, a .gitignore saved as UTF-16 — are in .gitignore not working.

Why does my image still contain node_modules from my laptop?

Probably because your .dockerignore has node_modules but the folder is nested (packages/api/node_modules), or the file sits next to a Dockerfile that isn’t at the root of the build context. Docker reads .dockerignore from the root of the context — the folder you pass to docker build. Use **/node_modules, as generated here.

Should I commit lock files?

Yes for applications: package-lock.json, poetry.lock, Cargo.lock, composer.lock, Gemfile.lock, go.sum and .terraform.lock.hcl make builds repeatable, so none of them are ignored here.

Should Terraform state be in git?

No. State files can hold passwords and keys in plain text, and two people working from two copies will overwrite each other. Keep state in a remote backend with locking — and if the lock gets stuck, see Error acquiring the state lock.

Terraform says “Inconsistent dependency lock file”

Commit .terraform.lock.hcl, and see what to run for each case.

Git refuses to merge unrelated histories

It often happens when a new repository got its own README or .gitignore on GitHub. See refusing to merge unrelated histories.

Where can I find the other Git commands?

In the Git Cheat Sheet, including how to undo almost anything.

Articles

Learn more

would be overwritten by merge
CI/CD

Git "Your local changes would be overwritten by merge": keep them, or throw them away

Fix git "Your local changes to the following files would be overwritten by merge" or checkout: commit, stash, or discard them, plus untracked files and servers.

Beginner · 3 min read

src refspec
CI/CD

Git "error: src refspec main does not match any": commit first, or use the right branch name

Fix Git "error: src refspec main does not match any" on push: you have no commits yet, or your branch is called master. Check with git branch, then commit or rename it.

Beginner · 4 min read

refusing to merge unrelated histories
CI/CD

Git "fatal: refusing to merge unrelated histories": when the flag is safe, and when it isn't

Fix Git "fatal: refusing to merge unrelated histories": why it happens, how to use --allow-unrelated-histories safely, and how to spot a wrong remote or shallow clone.

Beginner · 4 min read

Inconsistent dependency lock file
Infrastructure as Code

Terraform "Inconsistent dependency lock file": what to run, and what to commit

Fix Terraform "Inconsistent dependency lock file": run init or init -upgrade, resolve version constraints and checksum errors across platforms, and lock it down in CI.

Beginner · 4 min read

failed to compute cache key: … not found
Docker & Containers

Docker build "failed to compute cache key: … not found": why COPY can't see your file

Fix "failed to compute cache key … not found" and "COPY failed": the file is outside the build context, excluded by .dockerignore, or missing in CI.

Beginner · 4 min read

.gitignore not working
CI/CD

.gitignore not working: why Git still tracks the file, and how to fix it

.gitignore is ignored because the file is already tracked, the pattern is wrong or the file has the wrong encoding. Find the cause with git check-ignore -v.

Beginner · 4 min read

Error: Error acquiring the state lock
Infrastructure as Code

Terraform "Error acquiring the state lock": who holds it, and when force-unlock is safe

Fix Terraform and OpenTofu "Error acquiring the state lock": read the lock info, wait or find the running job, and use force-unlock only on a stale lock.

Intermediate · 4 min read