I want to be able to do the following:
Create a local branch based on some other (remote or local) branch (via git branch
or git checkout
Building slightly upon the answers here, I've wrapped this process up as a simple Bash script, which could of course be used as a Git alias as well.
The important addition to me is that this prompts me to run unit tests before committing and passes in the current branch name by default.
$ git_push_new_branch.sh
Have you run your unit tests yet? If so, pass OK or a branch name, and try again
usage: git_push_new_branch {OK|BRANCH_NAME}
e.g.
git_push_new_branch -> Displays prompt reminding you to run unit tests
git_push_new_branch OK -> Pushes the current branch as a new branch to the origin
git_push_new_branch MYBRANCH -> Pushes branch MYBRANCH as a new branch to the origin
function show_help()
{
IT=$(cat < Displays prompt reminding you to run unit tests
git_push_new_branch.sh OK -> Pushes the current branch as a new branch to the origin
git_push_new_branch.sh MYBRANCH -> Pushes branch MYBRANCH as a new branch to the origin
)
echo "$IT"
exit
}
if [ -z "$1" ]
then
show_help
fi
CURR_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$1" == "OK" ]
then
BRANCH=$CURR_BRANCH
else
BRANCH=${1:-$CURR_BRANCH}
fi
git push -u origin $BRANCH