3 # Makes checkout "just work" in terms of checking out the branch whether or not
4 # it exists locally or remotely.
6 # If the branch exists locally (e.g. foo), then just check it out
7 # If the branch exists remotely (e.g. origin/foo), then create a new local branch
8 # If the branch does not exist remote, then make a new local branch and push it
13 # See if it already exists
14 git rev-parse --verify --quiet $branch_name >/dev/null
15 if [[ $? -eq 0 ]] ; then
16 # Just checkout what they asked
17 git checkout "$branch_name"
19 # Make sure we have the latest origin/$branch_name to branch
21 exists_remote=$(git branch -r | grep -x " origin/$branch_name" | wc -l)
22 if [[ $exists_remote -eq 0 ]] ; then
23 # Specifying stable to get the last released code
24 git checkout -b "$branch_name" origin/stable
25 # Go ahead and put the branch out on the server
26 git push origin "$branch_name"
27 # Setup the merge property so that pulls come from the right place (instead of stable)
28 git config --replace-all "branch.$branch_name.merge" "refs/heads/$branch_name"
31 git checkout -b "$branch_name" "origin/$branch_name"