11

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?

Thomas S.
  • 5,804
  • 5
  • 37
  • 72

1 Answers1

17

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/
$
ephemient
  • 198,619
  • 38
  • 280
  • 391
  • Ah, so to remove a worktree, we just have to remove the working tree and then invoke `git worktree prune` on the worktree's original repository. – Thomas S. Jan 20 '18 at 06:38
  • 1
    @ThomasS. Actually, with Git 2.17+ (Q2 2018), `git worktree remove` will be enough: See my [answer here](https://stackoverflow.com/a/49331132/6309). – VonC Mar 17 '18 at 00:15