GitHub from the command line with hub

Get Quicker

Article from Issue 239/2020
Author(s):

The handy hub command-line tool lets you manage your GitHub repository from a terminal window, which can make it easier to automate repetitive tasks.

Hub is an extension to command-line Git that allows you to perform everyday GitHub tasks straight from the terminal. The hub [1] extension forms an important part of the standard toolset for working with GitHub, alongside tools like Prose [2], a text editor, and coding platforms like Atom [3].

There are several huge advantages to using hub. First and foremost, it saves you time by letting you clone or create GitHub private repositories from your command line. Because hub also makes use of the power inherent in the command line, you can also use it to automate repetitive tasks.

This article describes the benefits of hub. I'll give you an example of what hub can do, and then I'll take you through the basics of using it.

Advantages of hub

First, let's give credit where credit is due. The GUI that is used by GitHub is not a bad system. It allows beginners to start using GitHub easily, and even for advanced users, it offers a good selection of automated tools and an intuitive way to complete most common tasks.

There are times, however, when you just need a command line – either because you are simply more comfortable working from the command line or because your repos have grown in complexity and number, and you want a way of automating your workflow. Hub provides these benefits, allowing you to do anything you can with a command-line interface – from wildcards to scripting – and giving you all of this functionality in GitHub.

For users who are accustomed to working at the command line, hub is simply faster than working with the GitHub GUI – at least for complicated projects. But keep in mind that hub is intended for advanced users. If you're new to GitHub, it is a good idea to become familiar with the GitHub basics before jumping into hub.

Before You Begin

Hub integrates directly with your GitHub account, so it poses a potential security risk. This risk is relatively low, and most developers who wish to use hub will know how to mitigate it. But in the interest of due diligence, I'll point out that the standard advice applies: Make sure you encrypt the connection between your terminal and GitHub's servers, and incorporate GitHub into your password manager.

Installation

The first step in installing hub is to make sure that you've got the correct version of Git. At the command line, run the following command:

$ git --version

This command will return your Git version. In order to use hub, the version must be 1.7.3 or newer. If Git is missing, or if you have an older version, don't worry: You can easily install a new version. One of the most popular (and, to my mind, the best) ways to install it is to use Homebrew [4], an open-source package manager, but you can also use the package manager that ships with your OS.

To install brew, the command-line utility for Homebrew, enter the following command:

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

This command will install to ~/.linuxbrew, but you can sudo the command if you want to change this.

Now you can install hub using brew:

$ brew install hub

You can then do a sanity check by looking for the version of hub you have installed:

$ hub version
git version 2.25.0
hub version 2.14.1 #

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Perl: CMS with GitHub

    With its easy-to-use web interface, GitHub can be put to totally different uses than archiving code. For example, Perlmeister Mike Schilli used GitHub to deploy a content management system for simple websites.

  • Git Cheat Sheet

    Frequently used Git commands at a glance.

  • Perl: Collaborate with GitHub

    GitHub makes it easier for programmers to contribute to open source projects by simplifying and accelerating communications between project maintainers and people willing to contribute.

  • Git Hooks

    The pre-commit framework lets you automatically manage and maintain your Git hook scripts to deliver better Git commits.

  • Branch Management

    Git makes version control as simple as possible. To manage your Git branches successfully, you need to learn the ins and outs of git branch and git merge.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News