Monday, December 23, 2013

BASH scripting GIT branch creation

This creates a develop branch if it doesn't exist already

create_develop_branchifNotExists() {
branch="develop"

if git show-ref --verify --quiet "refs/heads/$branch"; then
#echo >&2 "Branch '$branch' exists."
echo ""
else
#read -p "Do you really want to create branch $branch " ans
#echo $ans
echo "Creating $branch branch"
git branch $branch
git branch -a #show all branches
fi
}


# And the following lines assume you've already checked in all your changes. It will switch to develop branch and merge your changes from master into develop branch and go back to master branch.

create_develop_branchifNotExists
echo "========== MERGING Current branch into develop branch ============="
git checkout develop
git merge master

git checkout master

No comments: