Cleaning up scripts to only include useful stuff.
[git-central.git] / scripts / checkout
1 #!/bin/sh
2
3 branch_name=$1
4
5 # See if it already exists
6 git rev-parse --verify --quiet $branch_name >/dev/null 
7 if [[ $? -eq 0 ]] ; then
8         # Just checkout what they asked
9         git checkout "$branch_name"
10 else
11         # Make sure we have the latest origin/$branch_name to branch
12         git fetch
13         exists_remote=$(git branch -r | grep -x "  origin/$branch_name" | wc -l)
14         if [[ $exists_remote -eq 0 ]] ; then
15                 # Specifying stable to get the last released code
16                 git checkout -b "$branch_name" origin/stable
17                 # Go ahead and put the branch out on the server
18                 git push origin "$branch_name"
19                 # Setup the merge property so that pulls come from the right place (instead of stable)
20                 git config --replace-all "branch.$branch_name.merge" "refs/heads/$branch_name"
21         else
22                 # Do the checkout
23                 git checkout -b "$branch_name" "origin/$branch_name"
24         fi
25 fi
26