How do I manage multiple branches with git worktree in a git repository? #12

Closed
opened 2025-12-30 12:46:42 +00:00 by jadudm · 1 comment
Owner

When I'm switching between branches for development and reviews, I can get confused. Is there an easier way?

When I'm switching between branches for development and reviews, I can get confused. Is there an easier way?
Author
Owner

Git worktrees are great for this:

Assuming that the repository is at <path>/main, do something like this:

git worktree add -b <branch_name> ../<folder_name> HEAD

This puts a new directory next to main, but it is a checkout of a new branch. In this way, each branch gets its own directory. Now, switching branches is a matter of switching directories.

Git worktrees are great for this: Assuming that the repository is at `<path>/main`, do something like this: ``` git worktree add -b <branch_name> ../<folder_name> HEAD ``` This puts a new directory next to `main`, but it is a checkout of a new branch. In this way, each branch gets its own directory. Now, switching branches is a matter of switching directories.
jadudm added the git label 2025-12-30 12:49:43 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jadudm/how-to-do-computer-things#12