Ruby .gitignore template
The Ruby template ignores build and test output, bundler state and debugger history, and uses leading slashes to keep those rules from matching directories deeper in the tree.
At a glance
- Category
- Language
- Patterns in this template
- 22 rules
- Directories ignored
- 10 of the 22 rules end in a slash, so they match directories only
- Also needs an OS template
- Yes. Nothing here matches file manager or editor artefacts.
- Typical companions
- Rails if this is an application, plus an editor and an OS template.
In detail
The leading slash is the defining feature of this template. A pattern such as /tmp/ matches only a tmp directory at the repository root, while tmp/ without the slash would match one at any depth. Ruby projects have a lot of common directory names, so the anchoring matters: it keeps /coverage/ from swallowing a coverage directory inside a fixture, and /pkg/ from matching an unrelated package folder deeper in the tree.
Gemfile.lock is the judgement call, and this template makes the choice appropriate to a gem rather than an application. A gem is a library: its lockfile pins only what its own CI tested against, and consumers resolve their own versions, so tracking it adds noise without adding safety. An application is the opposite case. Deploying without a committed lockfile means production can resolve a different set of gems than you tested, so if this is an app, delete the line.
The bundler rules cover /.bundle, which stores the local install path configuration, and /vendor/bundle, which is where gems land when you install them into the project rather than system wide. Both are the result of running bundle install and neither should travel. /lib/bundler/man is generated documentation from the same tool.
*.gem and *.rbc are the packaged gem file and compiled Ruby bytecode. The test output rules cover /spec/reports, /spec/examples.txt and /test/tmp, all of which are regenerated on every run and produce conflicts if two people commit them from different machines.
.byebug_history is worth calling out. It is the debugger's command history, and it records every expression you evaluated at a breakpoint. On a session spent debugging an authentication problem, that history very plausibly contains a token or a password you printed to check it.
Examples
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/
.byebug_history
.dat*
.repl_history
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/
/.bundle/
/vendor/bundle
/lib/bundler/man/
.rvmrc
Gemfile.lock22 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- Gemfile.lock is ignored by default here. For an application that is the wrong default: remove the line and commit the lockfile so deploys resolve the versions you tested.
- The leading slash anchors to the location of the .gitignore file, not to the repository root. In a nested .gitignore, /tmp/ means the tmp directory beside that file.
- /vendor/bundle is anchored, so gems installed into a nested engine or subproject under its own vendor directory are not covered by this rule.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →Rails .gitignore template
The Rails template is built around the encrypted credentials system: the encrypted file is committed, the key that decrypts it never is. Every rule explained.
PHP .gitignore template
The PHP template ignores the vendor directory and the .env file, and also ignores composer.lock, which most application projects should commit instead.
Python .gitignore template
A line by line read of the Python .gitignore template: bytecode caches, virtual environments, packaging output, test caches and the lib/ rule that bites.
Swift .gitignore template
What the Swift template ignores: the package build folder, Xcode user state, derived data and symbol archives, plus the Package.resolved decision it makes.
Kotlin .gitignore template
The Kotlin template covers the same class and archive output as Java, plus the .kotlin session directory the newer compiler writes into the project root.
Dart .gitignore template
The Dart template ignores the tool directory, generated docs and compiled JavaScript output, and ignores pubspec.lock, which an application should commit.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS