github/gitignore · Rust.gitignore

Rust .gitignore Template Explained

Why Rust.gitignore ignores the target directory, rustfmt backups, MSVC debug info and cargo-mutants output, and the change to recommend committing Cargo.lock.

Open in generator Open with VisualStudioCode, JetBrains, macOS

Rust.gitignore is a short template containing only the minimum rules a Cargo project needs. Most output ends up in a single target/ directory, so there are few rules.

The old template told you to ignore Cargo.lock for libraries, but the current template no longer has that rule. In 2023 the Rust team changed its recommendation and made committing Cargo.lock the default for all projects, including libraries.

Rules explained

PatternWhat it ignores and why
targetdebugCargo build outputThe folder where cargo build puts compilation results, incremental build caches and built dependencies. It can grow to several GB and is fully regenerated. Without a trailing /, files with the same name are ignored too.
**/*.rs.bkrustfmt backupsBackups that rustfmt leaves before modifying a file. The pattern starts with **/, so it matches at any depth.
*.pdbMSVC debug informationDebug symbol databases created when building with the Windows MSVC toolchain.
**/mutants.out*/Mutation testing outputOutput directories created by cargo-mutants (mutants.out, mutants.out.old). Because of the trailing /, the pattern matches only directories.
rustc-ice-*.txtInternal compiler error dumpsStack traces that rustc leaves in the current directory when it hits an internal compiler error (ICE). They are useful for bug reports but not needed in the repository.

Practical notes

Original template

Rust.gitignore6 rules
# Generated by Cargo# will have compiled files and executablesdebugtarget# These are backup files generated by rustfmt**/*.rs.bk# MSVC Windows builds of rustc generate these, which store debugging information*.pdb# Generated by cargo mutants# Contains mutation testing data**/mutants.out*/# rustc will dump stack traces when hitting an internal compiler error to PWDrustc-ice-*.txt# RustRover#  JetBrains specific template is maintained in a separate JetBrains.gitignore that can#  be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore#  and can be added to the global gitignore or merged into this file.  For a more nuclear#  option (not recommended) you can uncomment the following to ignore the entire idea folder.#.idea/

Templates from github/gitignore/Rust.gitignore @356fd7b (2026-09-11) · CC0-1.0

Often used together

More template explanations