Created
July 20, 2026 21:59
-
-
Save dpaluy/4304b0649e3b5d307363383465b6f265 to your computer and use it in GitHub Desktop.
Worktree Rails example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # .config/wt.toml | |
| # Rails + Postgres worktree setup with teardown | |
| # --- Setup --- | |
| # Step 1: secrets + env (master.key is gitignored, copy from primary worktree) | |
| [[pre-start]] | |
| master-key = "cp {{ primary_worktree_path }}/config/master.key {{ worktree_path }}/config/master.key" | |
| env = """echo 'PORT={{ branch | hash_port }} | |
| DB_NAME={{ repo }}_dev_{{ branch | sanitize_db }}' > .env""" | |
| # Step 2: deps | |
| [[pre-start]] | |
| bundle = "bundle install" | |
| # Step 3: database (unique per branch) | |
| [[pre-start]] | |
| db = "bin/rails db:create db:migrate" | |
| # Dev server on per-branch port, background after creation | |
| [post-start] | |
| server = "bin/rails s -p {{ branch | hash_port }}" | |
| # --- Teardown --- | |
| # Drops this worktree's DB before removal. Runs in the worktree being removed, | |
| # so it reads the local .env for the correct DB name. || true so a missing DB | |
| # never blocks branch removal. | |
| [pre-remove] | |
| drop-db = "bin/rails db:drop || true" | |
| # --- wt list URL column --- | |
| [list] | |
| url = "http://localhost:{{ branch | hash_port }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment