Ruby and Rails .gitignore Configuration
Complete .gitignore for Ruby and Rails projects. Covers bundle directory, gem files, tmp directories, database files, and Rails credential management.
Detailed Explanation
Ruby projects, especially Ruby on Rails applications, generate a wide variety of files that should be excluded from version control. The .gitignore needs to cover Bundler artifacts, Rails-specific files, and runtime data.
Bundler and gem patterns:
vendor/bundle/— When runningbundle install --deploymentorbundle install --path vendor/bundle, gems are installed locally. This directory behaves likenode_modules/and should not be committed.*.gem— Built gem packages. If you are developing a gem, the.gemfile is a distributable artifact, not source code..bundle/— Bundler configuration cache containing per-project settings.
Rails-specific patterns:
tmp/— Rails stores cache files, session data, PIDs, and socket files here. Everything intmp/is transient.log/— Application log files (development.log,production.log,test.log). These grow continuously and are machine-specific.db/*.sqlite3anddb/*.sqlite3-*— SQLite database files used in development. Production databases should never be in the repo.storage/— Active Storage uploaded files in local disk service (Rails 5.2+).public/assets/— Precompiled asset pipeline output. Generated byrails assets:precompileand should be built by CI.public/packs/— Webpacker output directory (Rails 5.1 to 6.x).node_modules/— If using Webpacker, Importmap, or JavaScript bundling via jsbundling-rails.
Credentials handling:
Rails 5.2+ uses encrypted credentials (config/credentials.yml.enc), which IS committed. The master key (config/master.key) is what you must ignore:
config/master.key
config/credentials/*.key
The encrypted file is safe to commit because it is useless without the key. Share the master key through secure channels like a password manager, never git.
What to commit: Gemfile, Gemfile.lock (always for applications), config/credentials.yml.enc, .ruby-version, and .rubocop.yml for consistent linting.
Spring preloader: Ignore spring/*.pid to prevent Spring process ID files from being committed. Spring is a Rails application preloader that keeps a process running in the background for faster boot times.
Use Case
A Rails team migrating from asset pipeline to jsbundling-rails needs to update their .gitignore to handle both legacy compiled assets and new JavaScript build output.