This is a python script for "hopping" branches. Hopping is defined as preserving the current working changes with the current branch. This will add all current changes to the working directory to a temp commit, then switch git branches, and pop any temp commits detected on the new branch.
You can alias this script as a git sub-command
git config --global alias.hop "!python /path/to/git_hop.py"
By default, the script will inject a post-checkout
hook into the .git/hooks
folder. This hook will check for a temp commit in the branch you just switched to (without using hop), and print a warning message if one is found.
You can disable this behaviour by toggling EMBED_HOOK
to false
These are the equivalent git commands
# git hop branch_2
git add -A
git commit -m "!!hop_temp_commit!!"
git switch branch_2
# ---
# git hop branch_1
git add -A
git commit -m "!!hop_temp_commit!!"
git switch branch_1
# if last commit is temp commit
git reset HEAD~1