How I use git worktree
I've been using git worktree for at least five years now.
Here's how I set things up at work.
Say I work on short_ruby project.
I create a folder called short_ruby and inside I have:
- `short_ruby/main` -> which will always remain as head main
- `short_ruby/pairing` is where I pull branches for code reviews, dig deeper into changes, or show draft code to a colleague.
- `short_ruby/feature_<id>` is a new worktree I create for each feature I work on, and I remove it when I'm done.
Why these folders:
- I always keep a local copy of the current main branch. This helps me review changes or start something new, since I can quickly check how production works if main is what's deployed.
- I also want to quickly access any branch I'm reviewing, while still being able to see the main branch. Having separate folders makes it easy to switch between them.
- I keep a folder for each feature, which is similar to using branches. The difference is that I can always check main or another branch while working on a new feature.
In case you wonder what do I do with DB:
- When using SQLite this problem is solved by default as each folder will have their own database
- When using with PostgreSQL/MySQL I keep a single database and always do: rails db:reset + rails db:migrate when I have to run migrations inside a folder. In practice it works well.