Git tips & tricks
Git worktrees (working w/ multiple branches at once)
tip
Erwin Btw, quick Git trick to make working with multiple branches easier, without having to switch back and forth:
- You can use Git worktrees to have multiple folders for different branches of the same repo. All worktrees use the same Git history on your computer, so creating one is fast (much faster than cloning).
- Limitation: you can only have a single Git worktree per branch
- My recommendation: keep a “main” folder for the main branch and moving between branches, create worktrees scoped to a specific branch you want to work on
- For example, I have folders named
monolith,monolith-tea-v5,monolith-cvd-plotsetc… next to each other
- For example, I have folders named
- Quick commands breakdown:
git worktree add path/to/folder branch-namecreates a worktree in the folder, checking out an existing branchgit worktree add path/to/folder -b new-branch existing-branchcreates a worktree in the folder by creating a new branch from an existing branchgit worktree remove path/to/folderremoves the worktree and folder
- Example: from the root of the repo, run
git worktree add ../monolith-my-branch my-branch - This will create a new folder named
monolith-my-branchnext to your regularmonolithfolder, using themy-branchGit branch - Important: when the new folder is created, the Python environment is not set up, so you’ll have to run through the usual steps
uv sync->source .venv/bin/activate->mono syncuvshould blast through the install because everything is cached