Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/bash
RED='\033[7;31m'
GREEN='\033[7;32m'
YELLOW='\033[7;33m'
NC='\033[0m' # No Color
# Put it to bin :)
# Usage: git-create-branch.sh #4487522 Create script for branch' -creating
# Result: git checkout -b 4487522_Create_script_for_branch_creating
ISSUE_NAME="${@:1}"
BRANCH_NAME=$ISSUE_NAME
BRANCH_NAME=${BRANCH_NAME//#/}
BRANCH_NAME=${BRANCH_NAME//\'/}
BRANCH_NAME=${BRANCH_NAME//:/}
BRANCH_NAME=${BRANCH_NAME//./}
BRANCH_NAME=${BRANCH_NAME//,/}
BRANCH_NAME=${BRANCH_NAME// /_}
BRANCH_NAME=${BRANCH_NAME//\//_}
BRANCH_NAME=${BRANCH_NAME//\\/_}
BRANCH_NAME=${BRANCH_NAME//__/_}
# Update master
printf "\n${YELLOW} UPDATE MASTER ${NC}\n\n"
git checkout master
git pull
# Try to create branch
printf "\n${YELLOW} TRY TO CREATE BRANCH ${NC}\n\n"
git checkout -b $BRANCH_NAME
# Couldn't? Then checkout to it!
if [ $? -gt 0 ]
then
printf "\n${YELLOW} SWITCH TO BRANCH ${NC}\n\n"
git checkout $BRANCH_NAME
printf "\n${YELLOW} MERGE MASTER ${NC}\n\n"
git merge master
fi
printf "\n${GREEN} DONE ${NC}\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment