Git Pro Tip: Let grb Handle Remote Branches for You

It seems like git has been picking up more and more traction in the web community, and tools like Tower and gitx seem to be making git tons more accessible to designers. One of my favorite features of git is how easy it makes branching. Most of the time that I work on a new feature I create a branch for it in my git repo, and I typically push that branch up to the server if it’s going to be around for more than a few hours. The commands for doing all of that can be hard to remember, though. Enter grb, short for git_remote_branch.

grb is a command line tool that makes creating remote branches both locally and on the server really easy. For example, to create a remote branch you’d typically have to create the new remote branch, fetch, make sure that no remote branch with the name you’d like to use already exists, create a new tracking branch, and then check out the new tracking branch. That looks something like:

1
2
3
4
> git push origin master:refs/heads/new_branch
> git fetch origin
> git branch --track testing origin/new_branch
> git checkout testing

But with grb this is as easy as:

1
> grb new new_branch

To remove a remote branch just run:

1
> grb rm new_branch

grb includes features for creating, removing, and renaming remote branches, as well as for pulling and tracking remote branches. It’s a tool I’ve been using for over a year now, and has been invaluable in my toolkit. It’s a piece of cake to install, too. Just make sure you have Ruby available and run:

1
> gem install git_remote_branch

On any modern Mac Ruby came preinstalled and on Windows it’s easy to install Ruby with the Ruby Windows Installer. You’ll want the gem command around anyway because tons of web projects like SASS are delivering their tools through RubyGems.

What tools are you using to help out with your version control workflow?

Free Workshops

Watch one of our expert, full-length teaching videos. Choose from HTML, CSS or WordPress.

Start Learning

Treehouse

Our mission is to bring affordable Technology education to people everywhere, in order to help them achieve their dreams and change the world.

Comments

2 comments on “Git Pro Tip: Let grb Handle Remote Branches for You

  1. I use the git bundle in Textmate. Ctrl+g is a lot faster for me than typing, and it handles most of the primary functions (including branching). This is a good tip though.

  2. If you’re using any recent version of git, there are much simpler ways of creating remote branches:

    git checkout -b mynewbranch # creates and checks out a new branch locally
    git push origin mynewbranch # pushes the new branch to your remote

    To remove the branch from remote:
    git push origin :mynewbranch

    I highly recommend http://cheat.errtheblog.com/s/git as a git resource.