I'm using git version 2.14.2.windows.2 and invoked
git worktree add <newpath> <branch>
on a "normal" repository to create a worktree. This created a new working tree structure at <newpath>
for the branch <branch>
and added .git/worktrees/<newpath-name>
with a couple of files.
When invoking
git worktree prune
from the <newpath>
it prints nothing and seems to do nothing (all the files in <newpath>
and <original-dir>/.git/worktrees
are kept). The Git documentation writes:
Prune working tree information in $GIT_DIR/worktrees.
which does not help much. What actually git worktree prune
does or should do? Am I wrong in the assumption that it would remove the worktree to undo the git worktree add
?
git worktree prune removes information about (non-locked) worktrees which no longer exist. For example, $ mkdir a $ cd a $ git init $ git commit --allow-empty --allow-empty-message -m '' $ git worktree add ../b $ ls .git/worktrees/ b $ rm -rf ../b $ git worktree prune $ ls .git/worktrees/ $
Th Working Tree in Git is a directory (and its files and subdirectories) on your file system that is associated with a repository. It's full of the files you edit, where you add new files, and from which you remove unneeded files.
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 ../hotfix creates new branch hotfix and checks it out at path ../hotfix .
In your case, you can just run git checkout refs/heads/master . It leads to detached HEAD state. refs/heads/master can be replaced with the specific commit. Create as many worktrees for a detached HEAD as you want to.
git worktree prune
removes information about (non-locked) worktrees which no longer exist. For example,
$ mkdir a
$ cd a
$ git init
$ git commit --allow-empty --allow-empty-message -m ''
$ git worktree add ../b
$ ls .git/worktrees/
b
$ rm -rf ../b
$ git worktree prune
$ ls .git/worktrees/
$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With