Skip to content

Instantly share code, notes, and snippets.

@tomlin7
Last active June 18, 2025 11:34
Show Gist options
  • Save tomlin7/e4dadf9df39ecaa1f7237fc69e447f76 to your computer and use it in GitHub Desktop.
Save tomlin7/e4dadf9df39ecaa1f7237fc69e447f76 to your computer and use it in GitHub Desktop.

git boomerang — Flip Your Git Staged

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 boomerang

You'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 pop
  • git stash --staged Stashes only the staged changes, leaves unstaged changes intact
  • git add . Stages all the unstaged changes
  • git stash pop Pops the originally staged changes back into the working tree (as unstaged changes)

Now you've flipped staged ⇄ unstaged. 🔄

Make It a Cool Git Alias

git config --global alias.boomerang '!git stash --staged && git add . && git stash pop'

Now you can use it anytime like:

git boomerang

Example

# Start with:
git status

# Shows:
#   modified:   a.py (staged)
#   modified:   b.js (unstaged)

git boomerang

# Now:
#   modified:   a.py (unstaged)
#   modified:   b.js (staged)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment