Git alias that flips your staged and unstaged changes (invert the index vs. working tree)
Given this:
[✔] staged_file.py (staged)
[✎] modified_file.js (unstaged)After running:
git boomerangYou'll get:
[✔] modified_file.js (now staged)
[✎] staged_file.py (now unstaged)It stashes only your staged changes, stages everything else, then restores the original staged ones back into your working directory — unstaged.Here's Exactly What You Want
git stash --staged && git add . && git stash popgit stash --stagedStashes only the staged changes, leaves unstaged changes intactgit add .Stages all the unstaged changesgit stash popPops the originally staged changes back into the working tree (as unstaged changes)
Now you've flipped staged ⇄ unstaged. 🔄
git config --global alias.boomerang '!git stash --staged && git add . && git stash pop'Now you can use it anytime like:
git boomerang# Start with:
git status
# Shows:
# modified: a.py (staged)
# modified: b.js (unstaged)
git boomerang
# Now:
# modified: a.py (unstaged)
# modified: b.js (staged)