Git remote branching made easy

The branching strategy using Git we have adopted at Real Travel allows us to share code branches back and forth, while maintaining a clean master. This also allows for us to develop code that we know will not be released until a later date. _A brief overview of it was covered in this post._ The tough part was remembering the commands to get local copies of our code out to other team members, but luckily there is a great gem plugin to do just that.

Shortened and less effort

To create a branch on the remote from a local branch that resides on your computer, no less than four lines of terminal commands are needed:

git push [remote_server] master:refs/heads/my_branch
git fetch [remote_server]
git branch --track my_branch [remote_server]/my_branch
git checkout my_branch

Granted this is only needed to be done once per remote branch creation, memorizing the correct steps can be a burden. Git already has a few extra steps to wrap your head around when it comes to adding, committing and pushing, so having an all-in-one command makes it that much better.

A few great developers have created an awesome gem that takes those four commands and compresses them into one simple line.

grb publish branch_name [origin_server]

This gem is called git_remote_branch and can be found here on RubyForge.

The above example relates to an already created branch on your local, but not currently found on the remote. If you are starting out knowing you will eventually want to share the code and want to create a new remote and local branch to be tracked at the same time, a quick create can be done:

grb create branch_name [origin_server]

There are other commands for delete, track and renaming branches which can be found on the page. When you run each command, it also outputs the steps to aid in memorization for the possibility of future use without the gem.

Installing the gem

All documentation can be found on the RubyForge page, but here is the gem install command.

To install the gem:

sudo gem install git_remote_branch --include-dependencies


Filed under: Code