Skip to content

Instantly share code, notes, and snippets.

@WahidinAji
Forked from vaidd4/git-worktree-cheatsheet.md
Created February 16, 2026 03:26
Show Gist options
  • Select an option

  • Save WahidinAji/6705978672a25a5c913c5c23505a9a49 to your computer and use it in GitHub Desktop.

Select an option

Save WahidinAji/6705978672a25a5c913c5c23505a9a49 to your computer and use it in GitHub Desktop.
A cheat sheet for Git Worktrees

Git Worktree Cheatsheet

Documentation

Setup a folder inside a repo with a specific commit of that repo.

Create a new worktree

git worktree add [-f] [--detach] [--checkout] [--lock] [-b <new-branch>] <path> [<commit-ish>]
  • -f, --force: Force if is already checked out by another worktree or if is already assigned a worktree.
  • --detach: to detach the HEAD. (see git checkout --detach)
  • --no-checkout: suppress checkout. (see git read-tree Sparse Checkout)
  • --lock: lock the worktree. (see git worktree lock)
  • -b <new-branch>: Create the branch <new-branch> from <commit-ish> or HEAD if none.
  • -B <new-branch>: Same + force if <new-branch> already exist and reset branch to <commit-ish> or HEAD if none.
  • <path>: Relative or absolute path to the worktree
  • <commit-ish>: Commit or branch to use as base.
git worktree list [--porcelain]
git worktree lock [--reason <string>] <worktree>
git worktree move <worktree> <new-path>
git worktree prune [-n] [-v] [--expire <expire>]
git worktree remove [-f] <worktree>
git worktree unlock <worktree>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment