Last active
August 7, 2022 09:55
-
-
Save j-po/732875e5f4b925e0bfff to your computer and use it in GitHub Desktop.
`pushd` and `popd`-style commands for git branches (in the place of directories)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# `pushd` and `popd`-style commands for git branches (in the place of directories) | |
# USAGE: `pushb <branch>; SOME_WORK; popb` | |
GITSTACK=() # stack of branches–just an array that we add to and access from the tail | |
GITSTASHCK=() # stack of stashes | |
function pushb { | |
GITSTACK+=`git symbolic-ref --short HEAD` | |
GITSTASHCK+=`git stash create` | |
git reset --hard # `git stash create` doesn't do this the way `git stash` normally does | |
git checkout $1 | |
echo ${GITSTACK[@]} | |
} | |
function popb { | |
git checkout ${GITSTACK[-1]} | |
unset GITSTACK[-1] | |
git stash apply ${GITSTASHCK[-1]} | |
unset ${GITSTASHCK[-1]} | |
echo ${GITSTACK[@]} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment