Last active
May 22, 2019 16:12
-
-
Save mkropat/168309e41e3551f7aaa86e2fe7913ed5 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
SUBDIRECTORY_OK=1 | |
OPTIONS_SPEC='git go [options] [branch] | |
-- | |
b,branch create and checkout a new branch | |
' | |
. "$(git --exec-path)/git-sh-setup" | |
checkout_opts= | |
while test "$#" != 0; do | |
case "$1" in | |
-b|--branch) | |
checkout_opts="-b" | |
;; | |
--) | |
shift | |
break | |
;; | |
*) | |
usage | |
;; | |
esac | |
shift | |
done | |
does_branch_exist() { | |
git rev-parse "$1" >/dev/null 2>&1 | |
} | |
has_upstream() { | |
git rev-parse "$1@{upstream}" >/dev/null 2>&1 | |
} | |
if [ -z "$1" ]; then | |
git pull --ff-only | |
exit | |
fi | |
upstream=origin | |
branch="$1" | |
if [ "$#" -gt 1 ]; then | |
upstream="$1" | |
branch="$2" | |
fi | |
git fetch "$upstream" "$branch:$branch" 2>/dev/null && | |
if ! has_upstream "$branch"; then | |
git branch --set-upstream-to="$upstream/$branch" "$branch" | |
fi | |
git checkout $checkout_opts "$branch" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment