Skip to content

Instantly share code, notes, and snippets.

@indiamos
Created January 26, 2022 19:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indiamos/3dd614fb3713b43de6c68fac7611be11 to your computer and use it in GitHub Desktop.
Save indiamos/3dd614fb3713b43de6c68fac7611be11 to your computer and use it in GitHub Desktop.
# Make pretty branch names, translated from https://gist.github.com/JoshNavi/8bc9a12b7492fc093b2c8b0bb8b0473e#create_branch
function create_branch() {
local branch_name=$argv[1]
if [[ -z "$branch_name" ]]
then
echo "Need to pass a branch name to use"
return 1
fi
# Change this to whatever your team's project key is
local ticket_key="YO"
local ticket_number=$argv[2]
# Change this to your name
local default_user="india"
local user=$argv[3]
if [[ -z "$user" ]]
then
user=$default_user
fi
local new_branch="$user/$branch_name"
if [[ -n $ticket_number ]]
then
local new_branch="$user/$ticket_key-$ticket_number/$branch_name"
fi
echo "Creating branch and checking out $new_branch"
command git checkout -b "$new_branch"
}
# Examples:
#
# create_branch the-branch-name
# git checkout -b ia/the-branch-name
#
# create_branch the-branch-name 111
# git checkout -b ia/YO-111/the-branch-name
#
# create_branch the-branch-name 111 mob
# git checkout -b mob/YO-111/the-branch-name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment