Remote Branches in Git
Here's a nice ruby script that will automatically create a remote tracking branch on your git repository! Assuming you have a remote bare Git repository:
Create a file in your script directory called create-branch with the contents below:
#!/bin/sh
# create-branch <branch_name>
if [ $# -ne 1 ]; then
echo 1>&2 Usage: $0 branch_name
exit 127
fi
echo [GIT] creating branch: $1
git push origin origin:refs/heads/$1
echo [GIT] updating with origin
git fetch origin
echo [GIT] checking out remote branch: origin/$1
git checkout --track -b $1 origin/$1
echo [GIT] pulling update from: origin/$1
git pull
echo [GIT] finished creating remote branch: origin/$1
echo [GIT] finished creating tracking branch: $1
Now to create your remote branch, change to your rails root directory and:
ruby script/create-branch <new_branch_name>
This is a great way to share branches with others and committing them to a repository. Central shared repositories are more of the SVN or CVS like mindset, while Git is designed in a way where you are not constrained to a central repository. I never really found a real world use case where I wanted people all chained together without any real central backed up repository, but hey, you never know.
