Skip to content

Instantly share code, notes, and snippets.

@oskarizu
Created May 3, 2013 14:52
Show Gist options
  • Save oskarizu/5509588 to your computer and use it in GitHub Desktop.
Save oskarizu/5509588 to your computer and use it in GitHub Desktop.
Simple script to create topic branches
#!/bin/sh
# Create automatic topic branches with your username or
# a specified name in .script_vars which has to be placed in
# $HOME directory
#
# .script_vars format
#
# usr=whatever
# from=whatever
#
if [ -f $HOME/.script_vars ]; then
. $HOME/.script_vars
else
user=$(whoami)
from="release"
fi
function check_git_repo() {
if ! git ls-files >& /dev/null; then
echo "You must be in a git repo!!!" && exit
else
git_topicb
fi
}
function git_topicb() {
read -p "Name of the branch to create: " t_branch
#Make a git pull from origin branch and create
#the topic branch from this repo
git checkout $from && git pull
wait
git checkout -b "$user/$t_branch"
wait
#Check if branch created is the desired branch
ck=`git rev-parse --abbrev-ref HEAD`
if [ $ck == $user/$t_branch ]; then
exit 0
else
echo "Something went wrong, sorry" && exit
fi
}
#First perfom a check if this is a git repo and perform the branch
check_git_repo && git_topicb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment