- Home
- Skills
- Alex Popov Tech
- .Dotfiles
- Git Worktree Remove
git-worktree-remove_skill
92
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill alex-popov-tech/.dotfiles --skill git-worktree-remove- SKILL.md3.5 KB
Overview
This skill removes git worktrees stored under the .worktrees/ directory and cleans up all administrative traces. It accepts a worktree name or runs an interactive selector when no name is provided. The script validates context, confirms with the user, forces removal if needed, and prunes leftover git metadata.
How this skill works
A bash script performs the removal by first confirming the current directory is a git repo and that .worktrees/ exists. It sanitizes the provided name (slashes converted to dashes), or lists available worktrees for interactive selection. The script then prompts for confirmation, runs git worktree remove --force, deletes the worktree directory, prunes git’s worktree administrative data, and removes .worktrees/ if it becomes empty.
When to use it
- Remove a temporary worktree after finishing a task
- Clean up old or abandoned worktrees to reduce clutter
- Free disk space used by unused worktrees
- Recover from leftover administrative entries after manual deletions
- Maintain a tidy .worktrees/ directory for dotfiles or complex repo workflows
Best practices
- Run the script from the repository root to ensure proper .git context
- Provide the sanitized worktree name (slashes will be converted to dashes) to skip the interactive prompt
- Review the confirmation prompt carefully; removal uses --force and can discard uncommitted changes
- Run git status and stash or commit local work before removal if you need to preserve changes
- Keep a backup or note of branch names if you rely on worktrees for long-lived branches
Example use cases
- Remove a named worktree after finishing a hotfix: scripts/remove_worktree.sh hotfix-123
- Use original branch format and let the script sanitize: scripts/remove_worktree.sh user.name/AOF-123 (removes .worktrees/user.name-AOF-123)
- Run without arguments to pick from a numbered interactive list of worktrees
- Clean up stale git metadata after manual deletions to avoid admin residue
- Automate cleanup in repo maintenance scripts after CI or feature branches are merged
FAQ
The script uses git worktree remove --force, which can discard uncommitted changes. Stash or commit changes before running if you need to preserve them.
I ran the script but .worktrees/ still exists. Why?
The script only removes .worktrees/ if it becomes empty. If other worktrees remain, the directory is kept to avoid data loss.
Can I supply a branch name instead of the sanitized folder name?
Yes. The script auto-sanitizes names by replacing / with -, so branch-style names work the same as the folder name.