Fast, disposable Git worktrees for AI agents and throwaway experiments.
temptree # create a disposable worktree with your uncommitted changes
# ... let an agent loose, experiment freely ...
rmtree # clean up and return to main repoCreates a detached worktree and copies your working tree into it (using copy-on-write when available), uncommitted changes included. Your main checkout stays untouched.
Create a temp worktree at HEAD (includes uncommitted changes):
temptree
# => ~/forest/myrepo-2137Name the worktree instead of getting a random number:
temptree -n experiment
# => ~/forest/myrepo-experimentSpecify a directory:
temptree -d /tmp/my-wtRemove a worktree by path:
rmtree ~/forest/myrepo-2137Remove the current worktree (when inside one):
rmtreeRemove a worktree outside the forest dir (requires --force):
rmtree -f /tmp/my-wtPreview what either command would do without making changes:
temptree --dry-run
temptree --dry-run -n experiment
rmtree --dry-run ~/forest/myrepo-2137Both scripts support -h/--help for quick reference.
- Put the scripts on your PATH:
# symlink (updates when you git pull)
ln -s "$(pwd)/temptree" "$(pwd)/rmtree" /usr/local/bin/
# or copy
cp temptree rmtree /usr/local/bin/- (Optional) Add shell helpers for auto-cd behavior:
Bash/Zsh:
cat shell_helpers.sh >> ~/.bashrc # or ~/.zshrcFish:
cat fish_helpers.fish >> ~/.config/fish/config.fishNushell:
open nushell_helpers.nu | save --append $nu.config-path| Action | Without helpers | With helpers |
|---|---|---|
temptree |
Prints new worktree path | cds into it |
rmtree |
Prints main repo path | cds back |
| Name | Default | Description |
|---|---|---|
TEMPTREE_FOREST_DIR |
$HOME/forest |
Base directory for temp worktrees (absolute path) |
TEMPTREE_PRUNE_FOREST |
1 |
Set to 0 to keep the forest dir when it becomes empty |
temptreecreates a detached Git worktree at HEAD- It then copies your entire working tree (including uncommitted changes and dotfiles) into the worktree, using CoW when available
- If no directory was specified, the worktree is named
<repo>-<random>under the forest dir (e.g.,~/forest/myproject-0042) rmtreeremoves the worktree viagit worktree removeand cleans up
Copy-on-write is auto-detected:
- macOS/APFS:
cp -c - Linux with reflink support:
cp --reflink=auto - Fallback: regular
cp -a
If creation fails partway through, the incomplete worktree is automatically cleaned up.
temptreeonly works inside a Git repositoryrmtreerefuses to delete worktrees outside the forest dir unless you pass-f/--forcermtreerefuses to delete the main worktree of a repository (even with--force)- Everything is copied: untracked files, ignored files, dotfiles, all of it
- The
.gitdirectory is the only exception (it's managed by Git's worktree mechanism)
76 tests (196 assertions) covering both scripts and shell helpers end-to-end:
bash test.sh- git-snapshot - zero-side-effect working tree snapshots for Git
- try - fuzzy-searchable experiment directories with auto-dating
MIT