Created
September 1, 2020 15:38
-
-
Save sneeu/8f9b948a30a5a2636ec4e56244186afd to your computer and use it in GitHub Desktop.
Switch between main (or master) and the most recent branch
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
# Switches between a "main" branch ($BRANCHES) and the last checked-out branch. | |
function main | |
set -l BRANCHES main master | |
for branch in $BRANCHES; | |
# Check if branch exists | |
if [ (git branch --list $branch) ] | |
# Check if branch is the currently checked-out branch | |
if not [ (git branch --show-current) = $branch ] | |
git checkout $branch | |
else | |
# Switch to the last used branch | |
git checkout - | |
end | |
break | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment