Skip to content

Instantly share code, notes, and snippets.

@sneeu
Created September 1, 2020 15:38
Show Gist options
  • Save sneeu/8f9b948a30a5a2636ec4e56244186afd to your computer and use it in GitHub Desktop.
Save sneeu/8f9b948a30a5a2636ec4e56244186afd to your computer and use it in GitHub Desktop.
Switch between main (or master) and the most recent branch
# 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