Skip to content

Instantly share code, notes, and snippets.

@hammeiam
Created October 16, 2015 05:56
Show Gist options
  • Save hammeiam/0b1df995d4514aec00fe to your computer and use it in GitHub Desktop.
Save hammeiam/0b1df995d4514aec00fe to your computer and use it in GitHub Desktop.
# Git Push Upstream
# A quick command for people that create a lot of feature branches
#
# Whereas `git push` will return an error if you haven't set the upstream branch
# `gpu` will automatically push to the correct upstream branch
# so you don't have to type `git push --set-upstream origin my_branch` for each new branch
function gpu() {
local RESPONSE=$( git push 2>&1 )
local UPSTREAM=$( echo "$RESPONSE" | grep -o "git push --set-upstream origin.*" )
# if we are given an upstream branch, push to that
if [ -n "$UPSTREAM" ]; then
echo "$UPSTREAM"
$UPSTREAM
else
# won't show the full "counting objects...delta compression...writing objects" response
echo "$RESPONSE"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment