Skip to content

she-llac/temptree

Repository files navigation

temptree

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 repo

Creates a detached worktree and copies your working tree into it (using copy-on-write when available), uncommitted changes included. Your main checkout stays untouched.

Usage

Create a temp worktree at HEAD (includes uncommitted changes):

temptree
# => ~/forest/myrepo-2137

Name the worktree instead of getting a random number:

temptree -n experiment
# => ~/forest/myrepo-experiment

Specify a directory:

temptree -d /tmp/my-wt

Remove a worktree by path:

rmtree ~/forest/myrepo-2137

Remove the current worktree (when inside one):

rmtree

Remove a worktree outside the forest dir (requires --force):

rmtree -f /tmp/my-wt

Dry run

Preview what either command would do without making changes:

temptree --dry-run
temptree --dry-run -n experiment
rmtree --dry-run ~/forest/myrepo-2137

Both scripts support -h/--help for quick reference.

Install

  1. 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/
  1. (Optional) Add shell helpers for auto-cd behavior:

Bash/Zsh:

cat shell_helpers.sh >> ~/.bashrc   # or ~/.zshrc

Fish:

cat fish_helpers.fish >> ~/.config/fish/config.fish

Nushell:

open nushell_helpers.nu | save --append $nu.config-path

With vs. without shell helpers

Action Without helpers With helpers
temptree Prints new worktree path cds into it
rmtree Prints main repo path cds back

Environment variables

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

How it works

  1. temptree creates a detached Git worktree at HEAD
  2. It then copies your entire working tree (including uncommitted changes and dotfiles) into the worktree, using CoW when available
  3. If no directory was specified, the worktree is named <repo>-<random> under the forest dir (e.g., ~/forest/myproject-0042)
  4. rmtree removes the worktree via git worktree remove and 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.

Notes

  • temptree only works inside a Git repository
  • rmtree refuses to delete worktrees outside the forest dir unless you pass -f/--force
  • rmtree refuses to delete the main worktree of a repository (even with --force)
  • Everything is copied: untracked files, ignored files, dotfiles, all of it
  • The .git directory is the only exception (it's managed by Git's worktree mechanism)

Testing

76 tests (196 assertions) covering both scripts and shell helpers end-to-end:

bash test.sh

See also

  • git-snapshot - zero-side-effect working tree snapshots for Git
  • try - fuzzy-searchable experiment directories with auto-dating

License

MIT

About

Fast, disposable Git worktrees for AI agents and throwaway experiments.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors