Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This script makes git automatically run `bundle install` when a merge conflict with Gemfile.lock occurs. Run it once per project to setup `.gitattributes` and `.gitconfig`
#!/usr/bin/env bash
# Usage: setup-git-bundler-merge-driver
# Help: Configures git to use a custom merge driver to resolve Gemfile.lock
# merge conflicts.
if [ ! -f Gemfile ]; then
echo 'No `Gemfile` found! Aborting'
exit 1
if [[ -z "$(git config" ]]; then
git config \
'Resolves Gemfile.lock merge conflicts by running `bundle install`'
echo "Added driver name"
if [[ -z "$(git config merge.bundler.driver)" ]]; then
git config merge.bundler.driver \
'echo Gemfile.lock merge conflict, running bundle install && bundle install --quiet'
echo "Added driver command"
if ! grep "Gemfile.lock merge=bundler" .gitattributes &> /dev/null; then
echo "Gemfile.lock merge=bundler" >> .gitattributes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.