Skip to content

Instantly share code, notes, and snippets.

@nickboldt
Last active December 12, 2015 07:58
Show Gist options
  • Save nickboldt/4740072 to your computer and use it in GitHub Desktop.
Save nickboldt/4740072 to your computer and use it in GitHub Desktop.
branching for stable milestone - create a new branch from master in both my fork and the origin
#!/bin/bash
usage ()
{
echo "Usage: $0 newbranchname"
echo "Example: $0 jbosstools-4.1.0.Alpha1"
exit 1;
}
if [[ $# -lt 1 ]]; then
usage;
fi
gituser=${GITUSER}
# read commandline args
while [[ "$#" -gt 0 ]]; do
case $1 in
*) branch="$1";;
esac
shift 1
done
if [[ ! $gituser ]]; then
echo "gituser is not set!"; exit 1
fi
if [[ ! $branch ]]; then
echo "branch is not set!"; exit 1
fi
if [[ $(git branch -a | grep $branch) ]]; then
echo "Branch $branch already exists."
else
echo "Creating new branch $branch ..."
git stash
# make us up to date
git checkout master
git pull nickboldt
git pull nickboldt master
git pull origin
git pull origin master
# create new branch, check it out, and push it to the server
git branch ${branch}
git checkout ${branch}
git push origin ${branch}
git push ${GITUSER} ${branch}
git stash pop
fi
# hub browse
projectName=`pwd`;projectName=${projectName##*/}
firefox https://github.com/jbosstools/${projectName}/tree/${branch}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment