Skip to content

Instantly share code, notes, and snippets.

@mmichaelis
Last active April 13, 2018 05:33
Show Gist options
  • Save mmichaelis/d92742202043269485b63b737022b78d to your computer and use it in GitHub Desktop.
Save mmichaelis/d92742202043269485b63b737022b78d to your computer and use it in GitHub Desktop.
Deletes a git working tree as sibling to your current workspace.
@('feature-1', 'bug-2') |
%{ $pattern = $_; $(
git worktree list | %{ $_.Split()[0] } | Select-String $pattern
)
} |
%{ Remove-Item -Recurse -Force $_ }; git worktree prune

Description

Will delete all worktrees given as first argument. This can either be a simple string or an array as given in the example to delete multiple worktrees.

Note that due to path limitations in Microsoft Windows Remove-Item might fail for too deep paths.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment