Profile avatar

Chizi Victor

Software Engineer

Git worktrees

Workflow for using git worktrees, cos I can never remember this shitâ€¦đŸ¥²

In order to get the worktrees feature on git, the repo needs to be a bare repository.

# creating a new repository
git init bare .

# cloning an existing repository
git clone --bare <remote:url>

Worktree commands

# Add a new worktree for an existing branch
git worktree add path/to/dir <existing-branch-name>

# Create worktree for a new branch
# from an existing branch
git worktree add -b <new-branch-name> path/to/dir <existing-branch-name>

# Remove worktree
git worktree remove path/to/dir

# List all worktrees
git worktree list