Added get push with interactive remote branch creation

This commit is contained in:
William Hilton 2015-07-18 20:26:56 -04:00
parent 46af3d420e
commit e57d03dd99

28
bin/get
View file

@ -1,8 +1,6 @@
#!/bin/bash #!/bin/bash
# I'm writing this in BASH because I hate myself, apparently. # I'm writing this in BASH because I hate myself, apparently.
list_branches() { list_branches() {
git for-each-ref refs/heads --format="%(refname:short)" git for-each-ref refs/heads --format="%(refname:short)"
} }
@ -149,4 +147,30 @@ echo 'Compare stage with HEAD'
git diff --cached HEAD git diff --cached HEAD
;; ;;
push)
echo 'Pushing'
# Check to see if upstream is set.
if git rev-parse --abbrev-ref @{upstream} >/dev/null ; then
git push
else
# Get local branch name
local_branch=$(git rev-parse --abbrev-ref HEAD)
# Check for multiple remotes
remote_count=$(git remote show | wc -l)
remotes=$(git remote show | tr '\n' ' ' | sed 's/\s*$//g')
if [ "$remote_count" = "1" ]; then
# If only one remote
remote="$remotes"
else
read -p "Which remote to push? (${remotes}): " remote
fi
read -p "Choose name for branch on '${remote}' [${local_branch}]: " remote_branch
if [ "$remote_branch" = "" ]; then
remote_branch="$local_branch"
fi
echo "I will run git push --set-upstream ${remote} ${remote_branch}"
git push --set-upstream ${remote} ${remote_branch}
fi
;;
esac esac