![Forrest logo](/images/logo.png)
git-worktree:tldr:73fa2
The git worktree prune
command is used to remove stale working tree references from the repository's GIT_DIR
or .git/worktrees
directory.
When you use the git worktree add
command, it creates a new working tree in a separate directory. Each working tree has a reference that is stored in the repository's GIT_DIR
or .git/worktrees
directory. These references, known as "worktree lockfiles," allow Git to keep track of the associated working trees.
Over time, it is possible for these references to become outdated or stale, especially if you delete or move the working tree manually without informing Git. Stale references can cause issues and inconsistencies in Git operations.
To remove stale references, you can run the git worktree prune
command. This command scans the repository's GIT_DIR
or .git/worktrees
directory and removes any lockfiles associated with working trees that no longer exist. By doing so, it ensures that Git's internal records are up to date and consistent with the actual state of the working trees.
It is a good practice to periodically run git worktree prune
in your repository to clean up any stale references and optimize the organization of your working trees.