Skip to content

FastTravelAS/rails-worktree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages