.gitignore & .dockerignore Generator
Ignore files for your stack, in one click.
● Runs 100% in your browser — nothing you type leaves this page.
# 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*.loglogs/*.tmp# macOS.DS_Store._*.AppleDouble.LSOverride# WindowsThumbs.dbehthumbs.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.jsnode_modules/dist/build/coverage/.npm/.eslintcache*.tsbuildinfonpm-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 --ignoredBoth 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
- Click what your project uses: languages, the editors and operating systems on your team, Terraform or Ansible.
- Switch between the .gitignore and .dockerignore tabs — they are generated together, for the same stack.
- Save both in the root of the repo. The link keeps your choice, so you can share it with the team.
What you get
- Secrets left out of both:
.envfiles and private keys — while.env.examplestays in git. - The exceptions that matter: the Gradle wrapper jar, shared
.vscode/settings.json, Rails’log/.keep, Terraform’s.terraform.lock.hclstay in git, even though the patterns around them are ignored. - A .dockerignore written for Docker’s rules, not git’s. In
.gitignore,node_modules/matches in every folder; in.dockerignore, every pattern starts at the root of the build context, so “anywhere” needs**/node_modules. Copying one file into the other quietly misses nested folders. - A smaller, safer build context: no
.gitfolder, no localnode_modulesor virtualenvs overwriting what the image installs, no.envbaked into a layer.
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
git check-ignore -v path/to/file # which line ignores this file (no output = not ignored)git status --ignored # see what is being ignoredgit rm -r --cached node_modules # stop tracking a folder git already tracks, keep it on diskgit ls-files -ci --exclude-standard # tracked files that your .gitignore says should be ignoreddocker build --progress=plain -t myapp . 2>&1 | grep "transferring context" # build context sizeWarning
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
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
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
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
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
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: 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
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