Git worktree management for Rails projects with isolated databases and configurations.
- 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
Add to your Gemfile:
group :development do
gem "rails-worktree"
endRun bundle install. A binstub will be automatically created at bin/worktree.
Manual binstub installation (if needed):
bundle exec rake worktree:installbin/worktree feature-branch # From current branch
bin/worktree feature-branch main # From specific branchThis creates a new worktree with:
- Separate databases:
myapp_feature-branch_developmentandmyapp_feature-branch_test - Copied configuration files (
.env,database.yml,Procfile.dev, credentials) - Copied
node_modules - Migrated and seeded databases
bin/worktree --close feature-branch # From main repo
bin/worktree --close # From within worktreeDrops both databases, removes the directory, deletes the branch, and cleans up git references.
The gem uses environment variables for database names:
DATABASE_NAME_DEVELOPMENT- Development database nameDATABASE_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:
- Sets these variables in the worktree's
.envfile - Updates the worktree's
database.ymlto use them - Creates both development and test databases with unique names
- Ruby >= 2.6.0
- Rails project with standard structure
- PostgreSQL (or modify for your database)
MIT