Should Gemfile.lock be included in .gitignore?

ghz 1years ago ⋅ 9046 views

Question

I'm sort of new to bundler and the files it generates. I have a copy of a git repo from GitHub that is being contributed to by many people so I was surprised to find that bundler created a file that didn't exist in the repo and wasn't in the .gitignore list.

Since I have forked it, I know adding it to the repo won't break anything for the main repo, but if I do a pull request, will it cause a problem?

Should Gemfile.lock be included in the repository?


Answer

Simple answer in the year 2021: Gemfile.lock should be in the version control also for Rubygems. The accepted answer is now 11 years old.

Some reasoning here (cherry-picked from comments):

@josevalim https://github.com/heartcombo/devise/pull/3147#issuecomment-52193788

The Gemfile.lock should stay in the repository because contributors and developers should be able to fork the project and run it using versions that are guaranteed to work.

@rafaelfranca https://github.com/rails/rails/pull/18951#issuecomment-74888396

I don't think it is a good idea to ignore the lock file even for plugins.

This mean that a "git clone; bundle; rake test" sequence is not guarantee to be passing because one of yours dozens of dependencies were upgraded and made your code break. Also, as @chancancode said, it make a lot harder to bisect.

Also Rails has Gemfile.lock in git: