Easier GitHub interactions with Hub

Have you ever been like: I wish I could just make the remote repository right from the prompt. With Hub it's possible.

Hub is pretty epic, I love it! Basically it make life easier by letting you interact with GitHub more from the command line and not from clicking GUI.

Install it

On a mac the best and easiest install method is via HomeBrew:

$ brew install --HEAD hub

Here’s a tutorial on how to install it to a Linux.

Then alias hub with git. Pop open ~/.aliases and add the following to the bottom of the file:

alias git=hub

Test if it works:

$ git --version
# If it returns the following, it works
git version 2.0.0
hub version 2.2.0

Configure Hub

Hub will prompt for GitHub username & password the first time it needs to access the API and exchange it for an OAuth token, which it saves in ~/.config/hub.

Test it out by creating a remote test repo:

$ mkdir git-test && cd git-test
$ touch README.md
$ git init
# Here's the sauce
$ git create

It’ll prompt you for a password and username. For whatever reason, it returned the following error for me:

Post ssh://api.github.com/user/repos: unsupported protocol scheme "ssh"

I changes protocol: to https in ~/.config/hub and it worked. The config file should look something like this:

- user: hilja
  oauth_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  protocol: https

Note worthy thing: you should authenticate to GitHub with SSH keys, see more here.

Note worthy thing #2: There’s a little gotcha in setting the protocol to https, because now GitHub prompts you a password every time you push or pull, it’s the intended behavior. Either, live with it, or cache your credentials, see GitHub tutorial how to do that.

Usage examples

If you’re unsure what the command does, you can safely test them with the --noop flag:

$ hub --noop create
git remote add -f origin https://github.com/hilja/git-test.git
echo created repository: hilja/git-test

It shows what it does, but does nothing.


First things first. This is from the docs:

git init -g OPTIONS
Create a git repository as with git-init(1) and add remote origin at "git@github.com:USER/REPOSITORY.git"; USER is your GitHub username and REPOSITORY is the current working directory’s basename.

Let’s test this with an example. First without Hub:

$ mkdir git-test && cd git-test
# Normal init
$ init
$ git remote -v
# The git remote command returns nothing cause there is no remote

Then with Hub:

$ mkdir git-test && cd git-test
# Hub init
$ git init -g
Initialized empty Git repository in /Users/hilja/code/git-test/.git/
$ git remote -v
origin  https://github.com/hilja/git-test.git (fetch)
origin  https://github.com/hilja/git-test.git (push)

With that you can skip the pointing to a remote step.


This is my favorite. So handy! Form the docs:

git create [NAME] [-p] [-d DESCRIPTION] [-h HOMEPAGE]
your GitHub username and REPOSITORY is the current working directory name. To explicitly name the new repository, pass in NAME, optionally in ORGANIZATION/NAME form to create under an organization you’re a member of. With -p, create a private repository, and with -d and -h set the repository’s description and homepage URL, respectively.

$ git create -d "This just a test repo, ignore"
origin  https://github.com/hilja/git-test.git (fetch)
origin  https://github.com/hilja/git-test.git (push)
created repository: hilja/git-test


The browse command will open project’s GitHub page into your default browser.

$ git browse
# Open issues
$ git browse -- issues
# Open pull requests
$ git browse -- pulls


If it’s your own repo, only a repo name is needed:

$ git clone test-repo

Not your own:

$ git clone someoen-else/test-repo

See the Hub website for more examples, or the man page for details.

Club-Mate, the beverage → club-mate.fi