Git - git-worktree Documentation
https://git-scm.com/docs/git-worktree, posted Jun '22 by peter in development documentation howto reference versioncontrol
In its simplest form,
git worktree add <path>automatically creates a new branch whose name is the final component of
<path>, which is convenient if you plan to work on a new topic. For instance,
git worktree add ../hotfixcreates new branch
hotfixand checks it out at path
../hotfix. To instead work on an existing branch in a new worktree, use
git worktree add <path> <branch>. On the other hand, if you just plan to make some experimental changes or do testing without disturbing existing development, it is often convenient to create a throwaway worktree not associated with any branch. For instance,
git worktree add -d <path>creates a new worktree with a detached
HEADat the same commit as the current branch.
If a working tree is deleted without using
git worktree remove, then its associated administrative files, which reside in the repository (see "DETAILS" below), will eventually be removed automatically (see
gc.worktreePruneExpirein git-config), or you can run
git worktree prunein the main or any linked worktree to clean up any stale administrative files.