Original source referenced: hub.packtpub.com (July 2019)
What Is Hub?
Hub is a command-line tool created by GitHub that wraps the standard git executable and adds GitHub-specific commands on top of it. Rather than switching between your terminal and a browser to manage pull requests, forks, and repositories, Hub lets you perform those operations directly from the command line.
Hub has no external runtime dependencies. Because it wraps git, the only prerequisite is having git installed — the project recommends git 1.7.3 or newer. Once configured, you can either call it as hub or alias it to git so that all your existing muscle memory continues to work.
Key Commands Hub Adds to Git
Hub provides both brand-new commands and extended versions of existing git commands. Some of the most useful ones include:
- hub am — Replicates commits locally from a GitHub pull request URL, making it easy to apply a PR to your local branch without manually fetching the remote.
- hub cherry-pick — Cherry-picks a commit directly from a fork on GitHub by accepting a GitHub commit URL instead of just a SHA.
- hub alias — Outputs shell instructions for aliasing
hubasgit, so allgitinvocations transparently gain Hub’s extra functionality. - hub browse — Opens the current GitHub repository in your default web browser from the terminal.
- hub create — Creates a new repository on GitHub and automatically adds a
git remotepointing to it, combining two steps into one. - hub fork — Forks the current repository on GitHub under your account and adds a git remote for the fork locally.
- hub pull-request — Opens a pull request on GitHub from the current branch without touching the browser.
- hub clone — Extends
git cloneso you can use shorthand likehub clone owner/repoinstead of full GitHub URLs.
The full list of commands is documented in the Hub man page (accessible via man hub after installation). Most commands are designed to run within an existing local git repository.
Why Use Hub? Core Use Cases
Contributing to Open Source
Hub simplifies the open-source contribution workflow considerably. Fetching a repository, navigating to the project page, forking a repo, and submitting a pull request can all be handled from the terminal without context-switching to a browser. This is particularly valuable when contributing to multiple projects in a single session.
Scripting and Automation
Because Hub is a CLI tool, it integrates naturally into shell scripts and CI pipelines. You can automate workflows such as creating GitHub issues on build failure, opening a pull request after a feature branch is pushed, or listing open issues as part of a triage script — all without needing to interact with the GitHub web UI or write custom API client code.
Project Maintenance
Maintainers benefit from Hub’s ability to fetch branches from contributor forks, review pull requests locally, and cherry-pick specific commits using GitHub URLs. This reduces the manual steps required to evaluate and merge external contributions.
Team and Enterprise Workflows
Hub supports GitHub Enterprise in addition to GitHub.com, though Enterprise hosts must be explicitly whitelisted in Hub’s configuration. For teams doing frequent code reviews, Hub can speed up the process of opening pull requests and pushing to multiple remotes in a single command.
Alternatives to Hub
Hub is not the only tool in this space. Notable alternatives include:
- GitHub CLI (
gh) — GitHub’s own official successor to Hub, released after 2019, which provides a more comprehensive and officially supported GitHub integration as a standalone tool rather than a git wrapper. - Lab — A similar CLI wrapper focused on GitLab workflows.
- Magit Forge — An Emacs-based interface for interacting with GitHub and GitLab forges from within the Magit git client.
Trade-offs and Criticism
While Hub is widely seen as convenient, some developers raise a legitimate concern: building workflows and automation around Hub deepens dependency on GitHub as a platform. As one Hacker News commenter noted at the time of its wider coverage:
“While it is pretty cool, using such a tool increases general lock-in to GitHub, in terms of both habits and potential use of it for automation of processes.”
This is a fair consideration for teams evaluating vendor neutrality. If your organisation might migrate to GitLab, Gitea, or another host, scripting workflows with Hub (or gh) creates migration overhead. For teams fully committed to GitHub, however, this trade-off is generally acceptable given the productivity gains.
Getting Started
Hub can be installed via common package managers. To alias it as git and check the version, run:
# macOS with Homebrew
brew install hub
# Alias hub as git in your shell profile
eval "$(hub alias -s)"
# Verify
git version # will show hub version alongside git versionCode language: PHP (php)
After aliasing, commands like git clone owner/repo, git fork, and git pull-request become available immediately in any existing git repository.
Note: If you are starting a new project today, consider evaluating GitHub’s official gh CLI, which has received active development and official support from GitHub since Hub’s initial rise in popularity.