2024-11-25

Using git work trees

Finally got to use git’s worktree command today. Had a case where I wanted to be on multiple branches at the same time (gotta love refactoring!!!).

Used the following commands:

git clone --bare url

# i wanted the main branch for reference when refactoring
git worktree add ../main-wt main

# i wanted to work on the refactor branch
git worktree add ../refactor-wt -b refactor

I used the --bare flag to clone because I didn’t want to have the files in the same directory as the original repo. I wanted to keep them separate.

References