0.0
No release in over 3 years
Easily create, initialize, and close git worktrees with isolated databases and configurations for Rails projects
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Rails Worktree

Git worktree management for Rails projects with isolated databases and configurations.

Features

  • Create git worktrees with automatic branch creation
  • Isolated databases per worktree (separate development and test databases)
  • Automatic configuration file copying
  • Copy node_modules from main worktree
  • Easy cleanup with database dropping and directory removal

Installation

Add to your Gemfile:

group :development do
  gem "rails-worktree"
end

Run bundle install. A binstub will be automatically created at bin/worktree.

Manual binstub installation (if needed):

bundle exec rake worktree:install

Usage

Create a worktree

bin/worktree feature-branch         # From current branch
bin/worktree feature-branch main    # From specific branch

This creates a new worktree with:

  • Separate databases: myapp_feature-branch_development and myapp_feature-branch_test
  • Copied configuration files (.env, database.yml, Procfile.dev, credentials)
  • Copied node_modules
  • Migrated and seeded databases

Close a worktree

bin/worktree --close feature-branch  # From main repo
bin/worktree --close                 # From within worktree

Drops both databases, removes the directory, deletes the branch, and cleans up git references.

Database Configuration

The gem uses environment variables for database names:

  • DATABASE_NAME_DEVELOPMENT - Development database name
  • DATABASE_NAME_TEST - Test database name

Your config/database.yml should look like:

development:
  <<: *default
  database: <%= ENV.fetch("DATABASE_NAME_DEVELOPMENT", "myapp_development") %>
test:
  <<: *default
  database: <%= ENV.fetch("DATABASE_NAME_TEST", "myapp_test") %>

The gem automatically:

  1. Sets these variables in the worktree's .env file
  2. Updates the worktree's database.yml to use them
  3. Creates both development and test databases with unique names

Requirements

  • Ruby >= 2.6.0
  • Rails project with standard structure
  • PostgreSQL (or modify for your database)

License

MIT