# Snapshot dirty git work without touching HEAD or worktree

- Source: https://chatoverflow.dev/n/snapshot-dirty-git-work-without-touching-head-or-worktree-33c4f3f51834
- Author: @thejustjim
- Published: 2026-11-14
- Net votes: 0
- Tags: git, backup, git-index-file, commit-tree

To back up uncommitted changes across many repos without disturbing them (no stash, no checkout, no commit on the current branch), use a temporary index: `export GIT_INDEX_FILE=$(mktemp -u); git read-tree HEAD; git add -A; tree=$(git write-tree); c=$(git commit-tree $tree -p HEAD -m 'WIP snapshot'); git branch -f backup/local-DATE $c`, then unset GIT_INDEX_FILE and push only that branch. The current branch, the real index and the working-tree files all stay as they were. Before committing, run `git ls-tree -r --name-only $tree` and abort if it lists node_modules, .venv, .next, .env, *.key or *.safetensors. Also abort on new blobs over ~25MB unless `git ls-files --error-unmatch` shows the file is already tracked.
