Git + Hub = Github – A guide to using Github’s hub for a faster workflow.

For those of you that aren’t familiar with Github’s “hub” project let me explain it to you.  It isn’t anything too crazy, but what it does is add some additional functionality to your existing git installation.  When I look at my workflow I realized that I am more often than not using Git to interact with Github, and this makes it just a little bit easier without breaking any of Git’s other functionality.  At any rate, here is how to get started using Github’s Hub.

Installation

I am going to cover both OSX installation and Linux installation, but I personally use OSX more than I do my Linux box, so understand that is where I am testing this.  If you happen to follow this guide and find any issues at all please leave a comment so that I can fix my guide and help you out.

For OSX

If you don’t already have Homebrew installed on OSX and you are a developer, you probably should.  It’s an easy install, but it’s outside of the scope of this guide so follow the instructions here.  After you have that installed just run this command:

Well, that was easy.

For Linux, specifically Ubuntu variants.

There are just a couple more steps with Linux because we can’t necessarily rely on Ruby being installed.

Now hub is installed and we can use it from the terminal using the command “hub”, but I want to take it a step further and according to Github we can safely alias “git” to “hub” without breaking anything.

To do this we just need to open up the .bashrc file (if you use bash, I use zsh so I opened ~/.zsh) and add a single line.

After adding that let’s simply source our respective rc file:

Now lets just double check and make sure that all is working properly.

You should have some output that shows the version of git and the version of hub.

Basic Usage.

I will cover some basic usage here, but if you want to get a little bit more in depth you can check out the git page of the project for more information.  It’s available here, additionally, it has a well-made man page that is actually easy to read and understand.

The main feature that I find to be useful is the shorthand Github cloning.  So instead of using the entire URL for a Github project, we can just enter the path to the project like this:

It makes pulling down projects quicker and easier, and that shorthand can be used all across Git.

After pulling down a repo, you can make a quick fork of the project with:

and start working within your own personal project immediately.  You can now make your changes and push to your personal repo with

and then open up a pull request with:

Personally, each one of these individual additions doesn’t add an incredible amount to Git, but as a workflow, it makes a huge difference.  Also, Hub is put together really well.  The workflow is elegant, it doesn’t add too much more to learn, and it doesn’t break anything for use outside of Github.

In conclusion, please let me know if I messed anything up or if you have ever had any issues with Hub.  Also, if you are a project maintainer there is a lot more stuff for you within hub for you, I am not so I have never used it.

Happy hacking everyone!

Daniel is a freelance web developer and IT consultant with a passion for security and privacy. Although he isn't much of a writer, he enjoys writing blog posts that help out others in the community.

Leave a Reply

Your email address will not be published. Required fields are marked *