Skip to content

Guide · Open source

How to use hub: GitHub commands for git in the terminal

Updated · written with AI from the project's own documentation and checked against our catalogue data

hub is a free, open-source command-line tool that wraps git and adds extra commands for working with GitHub. This guide shows you how to install it, run its main commands such as cloning by owner/name, and optionally alias it as git. By the end you will know whether it fits a daily terminal workflow.

hubmislav/hub · ★ 23k · MIT

Quick start

  1. 1Check your git version. Make sure git 1.7.3 or newer is installed, as the README recommends.
  2. 2Install hub. Use Homebrew, Scoop, Chocolatey or another listed package manager to install hub.
  3. 3Confirm the install. Run hub version to check the installed build, especially for community packages.
  4. 4Clone by owner/name. Run hub clone followed by owner/name, for example rtomayko/tilt, to clone over HTTPS.
  5. 5Optionally alias git. Run hub alias -s and add the eval line to your shell startup file to use hub features with git commands.
  6. 6Read the full reference. Check the README links for usage examples and the full reference documentation to see all commands and flags.

What hub does and who it is for

hub is a command line tool that wraps git to extend it with features and commands that make working with GitHub easier. Its normal git commands keep working, and it adds GitHub-specific ones on top, such as cloning a repository by its owner and name or handling pull requests from the terminal.

It suits developers who use git and GitHub every day from the terminal, and people who want familiar git commands with GitHub shortcuts. The project is MIT licensed and written in Go.

Install hub on your system

The hub executable has no dependencies, but because it wraps git, the README recommends git 1.7.3 or newer. Choose the package manager that matches your platform.

Packages other than Homebrew are community-maintained and may not match the latest hub release, so run hub version after installing one.

  • macOS or Linux with Homebrew
  • Windows with Scoop or Chocolatey
  • Fedora, Arch, Debian/Ubuntu, openSUSE, FreeBSD, Void, Gentoo and conda are also listed in the README
  • The README does not recommend the Ubuntu snap anymore
brew install hub scoop install hub choco install hub

Clone a repository with hub

Use hub clone with owner/name instead of a full URL. hub expands it into the matching git clone command over HTTPS by default.

If you prefer SSH, set the protocol in your git config first. After that, the same hub clone command produces an SSH clone URL.

$ hub clone rtomayko/tilt #=> git clone https://github.com/rtomayko/tilt.git $ git config --global hub.protocol ssh $ hub clone rtomayko/tilt #=> git clone git@github.com:rtomayko/tilt.git

Alias hub as git (optional)

Some hub features work best when it is aliased as git. The README says this is safe and that your normal git commands will all work; hub simply adds extra features. Run hub alias to see instructions for your shell, or use the -s flag to output a script for eval.

Add the eval line to a startup file such as .bash_profile. PowerShell users instead set a git alias to hub in their profile and restart the console.

  • Bash, zsh or similar: place the eval line in your startup script
  • PowerShell: add Set-Alias git hub to your profile, then restart PowerShell
eval "$(hub alias -s)"

Use hub in GitHub Actions and scripts

hub can run inside GitHub Actions workflows. The example lists open pull requests with hub pr list and passes the GITHUB_TOKEN secret as an environment variable.

The default secrets.GITHUB_TOKEN only works for API operations scoped to the repository running the workflow. For other repositories, the README says to generate a Personal Access Token with at least the repo scope and store it in your repository secrets. hub can also be used in shell scripts that interact directly with the GitHub API.

steps: - uses: actions/checkout@v2 - name: List open pull requests run: hub pr list env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Build hub from source

To build from source you need make and Go 1.11 or newer. Clone the repository with the README's flags, then run make install with a prefix.

cd hub make install prefix=/usr/local

Add tab completion

The hub repository includes tab-completion scripts for bash, zsh and fish. They complement the completion scripts that ship with git. The scripts live in the etc directory of the repository.

What people use it for

  • Clone a GitHub repository by owner/name without typing the full URL
  • Use git commands as usual while gaining GitHub shortcuts through the git alias
  • List open pull requests from a terminal or a GitHub Actions workflow
  • Write shell scripts that call the GitHub API

Frequently asked questions

How do I install hub?

On macOS or Linux, run brew install hub with Homebrew. On Windows, use scoop install hub or choco install hub. Other platforms are covered by package managers listed in the README.

What do I need before installing hub?

The hub executable has no dependencies. The README recommends git 1.7.3 or newer because hub is designed to wrap git.

Is hub free to use?

hub is open source and released under the MIT licence, as stated in the project's README and licence information.

Is hub the same as the GitHub CLI?

No. hub is a git wrapper, and the README points to cli.github.com as an official, potentially more user-friendly interface to GitHub. It also links a comparison document between gh and hub.

Is it safe to alias hub as git?

The README says aliasing is not dangerous and normal git commands still work, but hub adds features that change how the git command behaves in your shell. If you dislike tools that wrap git, skip the alias.

Where do I report a problem with GitHub.com itself?

The README says the hub issue tracker is not for problems with the GitHub.com web interface. For those, contact GitHub Support through the link in the README.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

hub suits developers who use git and GitHub daily from the terminal and want familiar git commands with GitHub shortcuts, or who write scripts against the GitHub API. If you want the official, more actively positioned tool, or you dislike anything that wraps or aliases git, pick GitHub's gh CLI or another option such as lazygit or git-extras.

Install options & downloads