Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 30 lines (21 sloc) 673 Bytes
#!/bin/sh
if [ "${1}" == "" ]; then
echo "git-switch <branch> [--all]"
exit 1
fi
NEW_BRANCH=${1}
CURRENT_BRANCH=$(git branch &>/dev/null; if [ $? -eq 0 ]; then echo "$(git branch | grep '^*' |sed s/\*\ //)"; fi)
if [ "${2}" == "--all" ]; then
git stash save --include-untracked --all autostash &>/dev/null
else
git stash save autostash &>/dev/null
fi
git checkout ${NEW_BRANCH}
if [ "$?" == "1" ]; then
git branch ${NEW_BRANCH}
git checkout ${NEW_BRANCH}
fi
AUTOSTASH=$(git stash list | grep "${NEW_BRANCH}: autostash" | tail -n 1 | cut -d":" -f1)
if [ "${AUTOSTASH}" != "" ]; then
git stash apply --index ${AUTOSTASH} && git stash drop ${AUTOSTASH}
fi