Git Worktree Commands

Posted on Feb 17, 2022

The following are commands useful for working with git worktrees:

# clone the URL
$ git clone --bare <URL> <desired-folder-name>
# add a worktree based off the main branch
$ git worktree add main
# add a worktree and a new branch
$ git worktree add -b branch-name folder-name 
# push a branch 
$ git push [--set-upstream] origin branch-name 
# update main
$ git pull origin main
# merge main into branch (or rebase)
$ git merge main 
# remove worktree 
$ git worktree remove [worktree-name]
# add worktree based on a branch
$ git worktree add worktree-name branch-name