Skip to content

Instantly share code, notes, and snippets.

@OneOfOne
Last active November 29, 2021 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OneOfOne/675a8bdf60608fcd76401d93696cc4ec to your computer and use it in GitHub Desktop.
Save OneOfOne/675a8bdf60608fcd76401d93696cc4ec to your computer and use it in GitHub Desktop.
git-push-new a little git helper to push a new branch and create a pull request.
#!/bin/bash
BRANCH=$(git symbolic-ref --short HEAD)
if echo $BRANCH | grep -q master; then
echo no master pushing
exit 1
fi
args=""
nopr=0
for arg in "$@"; do
if [ "$arg" == "--nopr" ]; then
nopr=1
else
args="$args $arg"
fi
done
if git remote show -n origin | grep -q $BRANCH; then
git push "$args" || exit 1
else
echo creating new branch
git push --set-upstream origin $BRANCH $args || exit 1
fi
[ "$nopr" == "0" ] && hub pull-request -o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment