.gitignore Generator

One input per line. Output is numbered to match the input order.
Pinned tools are listed in your favourites on the home page.Copies a link to this tool that carries your current input, so it opens ready to run.Gives you an iframe snippet for putting this tool on your own site.

Select templates to combine into a single .gitignore file.

Languages

Frameworks

Editors

OS

Ctrl+Enter Run  · Ctrl+Shift+C Copy  · Esc Clear

Understand .gitignore Generator

通过组合 20 个内置模板中的任意若干个,构建 .gitignore 文件,涵盖语言、框架、编辑器和操作系统。

How it works

每个模板都是一组精选的匹配规则——构建产物、依赖目录、编辑器状态、操作系统杂物——生成器会把你选中的那些拼接起来,并加上带标题的分节。Git 自上而下读取该文件,最后一条匹配的规则胜出,因此后面出现的取反规则(例如 !keep.me)会覆盖前面的排除。以斜杠结尾的规则只匹配目录,而不含斜杠的规则会在目录树的任意深度上匹配。

When to use it

  • 新建仓库时,希望在第一次提交之前就配好合理的排除规则。
  • 把语言模板与你的编辑器和操作系统组合起来,这也是现实中最常见的用法。
  • 往已有文件中追加某个框架的构建目录(React、Angular、Vue、Django、Terraform、Unity、Gradle、Maven)。
  • 提醒自己某套工具链会生成哪些产物、以及哪些绝不该提交。

Watch out for

  • .gitignore 不会取消跟踪一个已经提交过的文件。无论规则怎么写,Git 都会继续跟踪它——请运行 git rm --cached <path> 并提交,规则才会生效。
  • 忽略一个机密不等于保护了它。如果 .env 曾经被提交过,它就仍留在历史中,任何拿到克隆的人都能读到;请轮换该凭据并重写历史,而不要以为加了忽略就解决了。
  • 取反规则无法把被排除目录内部的文件重新纳入。一旦 build/ 被忽略,git 就再也不会进入其中,因此 !build/keep.txt 毫无作用——请改为排除 build/*,这样目录本身仍会被遍历。
  • 编辑器和操作系统相关的规则属于你个人的全局忽略文件,而不是大家共享的仓库。用 git config --global core.excludesFile ~/.gitignore_global,可以让 .DS_Store 和 .idea/ 不出现在同事们必须阅读的那个文件里。

Frequently Asked Questions

如何创建 .gitignore 文件?

选择你的语言(Node.js、Python、Java 等)以及任意编辑器或操作系统模板(VS Code、macOS、Windows)。点击生成,然后复制或下载结果,并把它保存为项目根目录下的 .gitignore。Git 在每次提交时都会自动读取这个文件。

如何在 VS Code 中创建 .gitignore 文件?

在 VS Code 中打开终端(Ctrl+`)并运行:curl -o .gitignore https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore ——或者使用本生成器,复制输出,把它粘进项目根目录下一个名为 .gitignore 的新文件。

为什么被忽略的文件仍出现在 git status 里?

如果这些文件在 .gitignore 创建之前就已被跟踪,git 仍会继续跟踪它们。请用 git rm --cached <file>(或用 git rm -r --cached . 处理全部已跟踪文件)把它们从索引中移除。文件仍留在磁盘上,但在下次提交后会从 git status 中消失。

How to Use .gitignore Generator

  1. Paste or type your input in the input area above.
  2. The tool processes your input automatically or click Run.
  3. Copy or download the result using the action buttons.
  4. Use Ctrl+Enter to run quickly from the keyboard.