'add' picks up all changes.
[git-central.git] / scripts / checkout
1 #!/bin/sh
2
3 branch_name=$1
4 exists_local=$(git branch | grep -x "  $branch_name" | wc -l)
5 exists_remote=$(git branch | grep -x "  origin/$branch_name" | wc -l)
6
7 if [[ $exists_remote -eq 0 ]] ; then
8         # Make sure we have the latest origin/stable to branch
9         git fetch
10         # Specifying stable to get the last released code
11         git checkout -b "$branch_name" origin/stable
12         # Go ahead and put the branch out on the server
13         git push origin "$branch_name"
14         # Setup the merge property so that pulls come from the right place (instead of stable)
15         git config --replace-all "branch.$branch_name.merge" "refs/heads/$branch_name"
16 else
17         if [[ $exists_local -eq 0 ]] ; then
18                 # Make sure we have the latest origin/$branch_name to branch
19                 git fetch
20                 # Do the checkout
21                 git checkout -b "$branch_name" "origin/$branch_name"
22         else
23                 # Just checkout
24                 git checkout "$branch_name"
25         fi
26 fi
27