hub is a nice commandline tool for interfacing with Github’s features that’s intented to use as an extension of commandline git. It can save a lot of browser-and-mouse interaction and I really love how it fits in my toolbox during everyday development. This is a short, personal blogpost on how I use hub and the features that stand out for me personally – your workflow may vary!

Installation

I use a Mac, so it was a matter of brew install hub, check out project’s readme for instructions on Linux or Windows.

Configuration

On a first run it will ask you to authorize GitHub API access. You can safely trust it since it’s an official tool provided by GitHub Team.

Since hub passes over git’s commands to actual git, it’s a good idea to alias hub as git, so that known aliases, mnemonics and muscle memory still work while being able to use hub’s additional features.

Believe me you can do a lot with it. If you learn it fully you can:

  • clone any-profile/repository-name without providing full GitHub cloning path. Same trick works also for adding new remote add profile/repo
  • push multiple,origin,locations which is super handy if doing some extra management and keeping multiple repositories in sync and it also works with fetch command.
  • merge <PULLREQ-URL> with same message as would be normally done on GitHub. Which when pushed will close the existing PR.
  • Plus a lot more new hub commands, like:
    • pr list to navigate through your list of Pull Requests and pr show to open immediately the Pull Request page in your favorite browser.
    • issue helps you to manage, view and list repository issues.
    • sync to keep in fast-forward sync all local branches.
    • release to ship new builds of code straight to GitHub. Sample script
    • create, fork and delete to make or destroy repositories on your GitHub account
    • compare and browse to open repository page or change-set in your browser

What I use it for

In one project we have a lot of small repositories, cloning them via ssh is now a matter of issuing:

git clone project/repo-name

I don’t have to go to GitHub repository page and copy the full path to checkout repository locally. If I want to open the project in browser then I just type: git open and in the browser I can see exactly the same branch I had opened on my local machine.

Sometimes for a code review I need to open the code locally. With hub I can do it without opening the browser.

$ git pr list
      #5  Improved images handling   ready for review
      #4  Test tool. WEB UI to handle Customizations.   wip 

And then to checkout the branch locally in code-review branch I use git pr checkout 5 code-review

Whenever I need to view the PR in browser I can type: git pr show.

I can easily merge the pull-request’s branch in plain console. So let’s first copy the PR link to clipboard: git pr show -c and then checkout the upstream: git checkout develop. Now we are ready to merge the pull request and push it to upstream:

$ git merge <PULLREQ-URL from clipboard>
$ git push 

The merge command also works with --squash argument if needed. This way we achieved the ability to perform entire flow of working with pull request without leaving the console.

Creating pull requests

But there is more and hub allows to make a new PR. After running:

$ git pull-request -b develop -m 'Your PR title' -l "wip" -a Jim -c 

It will make the brand new PR with base branch set as develop with message as specified, particular label and even assignment. Last argument will copy the PR link to clipboard so it will be very fast to paste the PR on your team Slack or wherever you’d like to. I encourage you to examine all options that are possible for the pull-request command.

Checking build status

When we have a PR ready last thing to do from command line is to check the status of your work from CI system. Simple git ci-status shows it for you. But there’s more.

If you add -v for verbosity you can see more details of your build like a link and which service was running it.

$ git ci-status -v 
✔︎      danger/danger                   https://github.com/project/repo-name/pull/432#issuecomment-516876489
✖︎      Travis CI - Pull Request        https://github.com/project/repo-name/runs/200701337

Last thing is that you can immediately open browser page of the check for you with command like below:

$ open `git ci-status -f " %U"`

If you use other system than MacOS try other opener command, but you should get the point.

Conclusion

These were just a few features of hub, the ones I use everyday and why I recommend fellow developers to give it a try. It allows me to do more within the cozy world of commandline console and save on interacting with browser and mouse.