Skip to content
Browse files

re-add git-switch

  • Loading branch information...
1 parent 05a56bd commit e55ca7f5b67d6af857b9ac8d76c3a2f250778e7a @ddollar committed
Showing with 23 additions and 0 deletions.
  1. +23 −0 git-switch
View
23 git-switch
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+if [ "${1}" == "" ]; then
+ echo "git-switch <branch>"
+fi
+
+
+NEW_BRANCH=${1}
+CURRENT_BRANCH=$(git branch &>/dev/null; if [ $? -eq 0 ]; then echo "$(git branch | grep '^*' |sed s/\*\ //)"; fi)
+
+git stash save autostash &>/dev/null
+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 ${AUTOSTASH} && git stash drop ${AUTOSTASH}
+fi

0 comments on commit e55ca7f

Please sign in to comment.
Something went wrong with that request. Please try again.