Toolvito

Works on this device

Gitignore Generator

Tick the languages, operating systems and editors of your project to make a .gitignore file. You can also check whether a path is ignored by a set of rules, and see what each line of a .gitignore file does.

Enter your values

Tick your languages, tools, operating systems and editors. The file lists the files and folders that Git should not track.

Your values

One pattern on each line. They go at the end of the file, so they win over the lines above.

Your values are worked out in this browser. They are not sent to a server.

Your file will show here

Tick the lists you need and choose Make the file.

How to use the generator

  1. Choose Make a .gitignore file and tick the lists you need, such as Node.js, macOS and Visual Studio Code.
  2. Add your own lines at the end if you like, such as a folder of local notes.
  3. Choose Make the file. Copy the text, or download it, and save it as .gitignore in the top folder of your repository.
  4. To test rules, choose Check whether paths are ignored, paste the rules and some paths, and choose Check. The table shows the line that decides each path.

The pattern rules of .gitignore

  • One pattern on each line. Blank lines and lines that start with # are not patterns. Write \# for a name that starts with #.
  • A slash at the end (build/) matches folders only. Without it, a pattern matches files and folders.
  • A slash at the start or in the middle (/build, docs/api) ties the pattern to the top folder of the repository. A pattern without such a slash (*.log, build/) matches in any folder.
  • Wildcards: * matches any characters except a slash, ? one character, and [abc] or [a-z] one character from the list. [!a-z] is any character not in the list.
  • Two stars: **/logs means logs in any folder, logs/** means everything inside logs, and a/**/b means b inside a, at any depth.
  • `!` at the start brings back a path that a line above ignored. The last line that matches a path decides.
  • An ignored folder is closed. Git does not look inside an ignored folder, so !logs/keep.txt cannot bring back a file when logs/ is ignored. Write logs/* instead, then !logs/keep.txt.
  • Spaces at the end of a line are dropped. A backslash makes the next character plain, so use / between folders, never \.

Worked example

With the lines node_modules/, *.log, !important.log, /build, logs/ and !logs/keep.txt:

  • debug.log is ignored by *.log, but important.log is not ignored: the later line !important.log brings it back.
  • build/output.js is ignored because the folder build at the top is ignored by /build. src/build/notes.txt is not ignored, because /build only matches at the top.
  • logs/keep.txt stays ignored: the folder logs is ignored, so the line !logs/keep.txt cannot work. The Explain calculation points this out.

Where the lists come from

The lists are short starting lists of common practice for each language, tool, operating system and editor, written for this page. Larger collections, such as the github/gitignore templates, have longer lists for more tools. Check any list against your own project: add the build folders, caches and secret files of your setup.

Limits you should know

  • A file that Git already tracks stays tracked when you add it to .gitignore. Remove it from Git with git rm --cached and its path, then commit.
  • The check reads one .gitignore file in the top folder. Git also reads .gitignore files in sub-folders, .git/info/exclude and a global ignore file; those are not read here.
  • Capital and small letters count as different unless you tick the box for core.ignoreCase, which is usually on for repositories on Windows and macOS.
  • In a real repository, git check-ignore -v and the path shows the line that decides it.

Related tools