Make Your "git" Command Awesome
I just stumbled on a cool command-line utility put out by GitHub called "Hub". It attempts to mimic the
git command while adding lots of useful functionality for GitHub Users.
To give you a taste, I'll demonstrate a common GitHub task with plain old
git, and then with the new
Cloning a repository
Hub provides simple cloning functionality that saves you a trip to the browser to grab a repository's url. Now, you can just reference the name of the repository you wish to pull down.
git clone https://github.com/laravel/framework.git
hub clone laravel/framework
Have I piqued your interest? Let's dive in.
I'm assuming you are on a Mac using homebrew, if not, go here for more details.
brew install hub
Setting up an alias
If you'd like, you can keep the
git command and
hub command separate. However, I did come across this line in the docs:
hub can be safely aliased as git so you can type $ git in the shell and get all the usual hub features.
I think this is pretty cool, so I opted to go this route. Add the following command to your
After restarting your shell, or running
source ~/.bashrc, your
git command is now supercharged with all of the features from
Note: you can also run
hub alias for instructions on aliasing.
Let's go through my favorite use cases for using
hub. If you're curious, you can head to the documentation to discover more things I haven't covered.
Initializing a GitHub repository
It's common for me to start work on a project locally, then eventually create a GitHub repository for it. Hub makes this process a little easier.
Now, a repository named after the current folder will have been created on my GitHub account, and my local git repo will be linked to it.
Forking a repository
If you pulled down a public repository and want to contribute to it by making pull-requests off your own fork. Hub makes that process simple:
The above command will fork the repo on your GitHub account and add the remote reference for you.
Opening a pull-request
From within a separate branch (that has been pushed to GitHub), run:
A Vim window will open where you can type the title and description. Upon closing the Vim window, the pull-request will be created and its URL will be provided to you.
Checking out a contributor's PR locally
If a developer makes a pull-request to a GitHub repo that you maintain, you may want to checkout their branch locally. Here's how you would accomplish that using Hub.
git pr checkout <The PR number>
If you don't know the number, you can view a list of open PRs directly from the command line using:
git pr list
This is something I usually copy and paste from GitHub, but now, with the much simpler Hub API, I can pull PRs down easily.
Publishing a release
This one is my personal favorite: the ability to create and tag a release on GitHub directly from the command line. Simply pass the release name to the
git release create command.
git release v1.3.1
After running that command a Vim window will open, prompting you to add a title and description if you wish.
To me, Git and GitHub go hand in hand. Having a tool that unifies operations from both is a big time saver.
Enjoy the time savings!