github/gitignore · Rails.gitignore

Ruby on Rails .gitignore Template Explained

Why Rails.gitignore ignores log, tmp and storage, the development SQLite database, master.key, precompiled assets and node_modules, and how the .keep negation structure works.

Open in generator Open with Ruby, Node, macOS

Rails.gitignore blocks the files a Rails application creates while running and its secrets. Its main targets are data the server accumulates as it runs, such as logs, temporary files and uploads, and the output of the asset pipeline.

The pattern of excluding only a folder's contents while keeping an empty marker file, as in /log/* and !/log/.keep, appears three times. git does not store empty directories, so this approach is needed to keep the folder structure.

Rules explained

PatternWhat it ignores and why
/log/*/tmp/*/storage/*!/log/.keep!/tmp/.keep!/storage/.keepLog, temp and storage foldersFolders where run logs, cache and pid files, and Active Storage local uploads accumulate. The contents are excluded but the .keep files are restored so the folders remain in the repository. If you exclude the directory itself, as in /log/, .keep cannot be restored.
config/master.keyconfig/initializers/secret_token.rb.env.env*.localSecret keysconfig/master.key is the key that opens the encrypted credentials.yml.enc. If this file leaks, every credential is exposed, so never commit it. The encrypted credentials file itself can be committed.
/db/*.sqlite3/db/*.sqlite3-journal/db/*.sqlite3-[0-9]*Development databasesSQLite files for development and testing. Commit db/schema.rb and the migrations, and let everyone create their own data files.
/public/assets/public/packs/public/packs-test/public/system/public/uploadsPrecompiled assets and packsOutput of assets:precompile and Webpacker, plus uploaded files. They are recreated during deployment.
/.bundle/vendor/bundlenode_modules//vendor/assets/bower_components/yarn-error.log.yarn-integrityBundler and Node dependenciesGems and JavaScript packages that come back when you install, and installation logs.
/coverage//spec/tmpcapybara-*.htmlrerun.txtpickle-email-*.html.rspecTest by-productsCoverage results, pages Capybara saves on failure, and Cucumber rerun lists. .rspec is treated as a personal RSpec options file.
.byebug_history.rvmrc.powenv*.rbc*.origPersonal tool settingsDebugger history, old RVM and Pow settings, and original backups left by merge tools.

Practical notes

Original template

Rails.gitignore38 rules
*.rbccapybara-*.html.rspec/db/*.sqlite3/db/*.sqlite3-journal/db/*.sqlite3-[0-9]*/public/system/coverage//spec/tmp*.origrerun.txtpickle-email-*.html# Ignore all logfiles and tempfiles./log/*/tmp/*!/log/.keep!/tmp/.keep# TODO Comment out this rule if you are OK with secrets being uploaded to the repoconfig/initializers/secret_token.rbconfig/master.key# Only include if you have production secrets in this file, which is no longer a Rails default# config/secrets.yml# dotenv, dotenv-rails# TODO Comment out these rules if environment variables can be committed.env.env*.local## Environment normalization:/.bundle/vendor/bundle# these should all be checked in to normalize the environment:# Gemfile.lock, .ruby-version, .ruby-gemset# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:.rvmrc# if using bower-rails ignore default bower_components path bower.json files/vendor/assets/bower_components*.bowerrcbower.json# Ignore pow environment settings.powenv# Ignore Byebug command history file..byebug_history# Ignore node_modulesnode_modules/# Ignore precompiled javascript packs/public/packs/public/packs-test/public/assets# Ignore yarn files/yarn-error.logyarn-debug.log*.yarn-integrity# Ignore uploaded files in development/storage/*!/storage/.keep/public/uploads

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

Often used together

More template explanations