Skip to content

Instantly share code, notes, and snippets.

@eguven
Created September 25, 2014 15:48
Show Gist options
  • Save eguven/b8c6b1df85b06ca7bc52 to your computer and use it in GitHub Desktop.
Save eguven/b8c6b1df85b06ca7bc52 to your computer and use it in GitHub Desktop.
gief_new_branch
# gief_new_branch <new_branch> [<start_point>]
# fetch 'upstream' named remote and branch out from 'upstream'/<start_point>
# git fetch upstream && git checkout -b <new_branch> upstream/[<start_point>]
function gief_new_branch()
{
local EFG="\033[0;31m"
local QFG="\033[32m"
local NC="\033[0m"
echo -e "${EFG}"
if [ ! -d $PWD/.git ]; then
echo -e "No git repo here bro${NC}"
return 1
elif [ -z "$(git remote -v | grep upstream)" ]; then
echo -e "No remote with name 'upstream' bro${NC}"
return 1
elif [ -z $1 ]; then
echo -e "Expected branch name bro${NC}"
return 1
fi
if [ ! -z "$(git status --porcelain)" ]; then
echo "There are uncommitted changes bro${NC}"
return 1
fi
local new_branch="$1"
echo -e "${NC}"
if [ ! -z $2 ]; then
echo "Setting base branch to $2"
local start_point="upstream/$2"
else
local start_point="upstream/master"
fi
git fetch upstream
git checkout -b ${new_branch} ${start_point}
echo -e "\n${QFG}$(wget --timeout=2 -qO - http://www.iheartquotes.com/api/v1/random?source=literature)${NC}\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment