Skip to content

Instantly share code, notes, and snippets.

@vaidd4
Last active January 24, 2024 15:58
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vaidd4/05a7580f725a2262fa9a3ddf8bdb11c1 to your computer and use it in GitHub Desktop.
Save vaidd4/05a7580f725a2262fa9a3ddf8bdb11c1 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