Science and technology

Install hub to make your Git command-line as totally featured as GitHub

Many persons are turning into concerned with open supply software program growth by contributing to initiatives on GitHub. Many of them use GitHub’s graphical consumer interface (GUI), particularly those that are new to the command-line interface (CLI). But what if you happen to want engaged on the command line?

I lately got here throughout hub, a command-line software that extends Git by including GitHub-specific options to make it simpler to turn into conversant in Git instructions. So, if you happen to’re bored with point-and-click GUIs however need some assist with Git’s generally complicated syntax, hub is the software for you.

Before studying additional, it is a good suggestion to review Git terminology first.

Installing hub

The use of hub is dependent upon Git, so first, verify we’ve it put in:

git --version

Your Git model have to be 1.7.three or newer. Don’t fear if it is lacking; you possibly can rapidly set up it utilizing Homebrew, an open supply bundle supervisor, or the built-in bundle supervisor on your distribution (dnf, apt, and so on). I like Homebrew, so we are going to follow that. Homebrew was beforehand generally known as Linuxbrew on Linux, but it surely now makes use of the identical identify because the macOS model. It may be put in in your house listing, which suggests you do not want sudo permission to put in purposes with it. If you like one other set up technique, see the Git documentation

To set up brew, Homebrew’s command-line utility, on Fedora:

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

Since we did not use sudo, the set up script installs Homebrew to ~/.linuxbrew. To be taught extra about the way it works, see the documentation.

Next, let’s set up hub utilizing brew.

$ brew set up hub

Next, confirm hub is put in accurately by checking its model:

$ hub --version
git model 2.25.zero
hub model 2.14.1

The output exhibits the variations of each hub and Git. Voila! You have efficiently put in hub.

Getting began with hub

Give hub a spin utilizing a brand new repository you’ll host on GitHub. Navigate to any folder the place you need to initialize Git:

$ cd Documents
$ mkdir Test; cd Test/
$ git init
Initialized empty Git repository in /Users/SudeshnaSur/Test/.git/

Place any file inside it. Git solely sees information which have modified, so add some textual content to it utilizing echo:

$ echo "Hello" > take a look at.txt

Check the git standing and add:

$ git standing
On department grasp

No commits but

Untracked information:
        take a look at.txt

nothing added to commit however untracked information current
$ git add .

By utilizing git add, we’ve staged the modifications however not but dedicated them. We want an account earlier than we do this. If you do not have already got one, create a GitHub account utilizing this step-by-step guide. Next, we have to configure our native model of Git to make use of the account’s username and electronic mail. This info might be in each commit message you add to any repository (since you might be setting it to be international):

git config --global consumer.electronic mail "[email protected]"
git config --global consumer.identify "Your Name"

It is value noting you may make your electronic mail to be personal utilizing this feature. Either manner, set your electronic mail to your GitHub electronic mail tackle.

Now, we are able to create a commit that might be assigned to our username. Let’s verify within the current change:

$ git commit -m 'Adding a take a look at file'
[grasp (root-commit) 07035c94e038] Adding a take a look at file
 1 file modified, 1 insertion(+)
 create mode 100644 take a look at.txt
$ git standing
On department grasp
nothing to commit, working tree clear

Using the flamboyant options of hub

Up to now, the whole lot has been the identical as utilizing git. Here is the place it will get attention-grabbing.

Now if you happen to sort hub create, it would create a brand new repository on GitHub with the identical identify as the present listing:

$ hub create
Updating origin
https://github.com/SudeshnaSur/Test

Using hub even hyperlinks your repository with the distant mirror:

$ git distant -v
origin  git@github.com:SudeshnaSur/Test.git (fetch)
origin  git@github.com:SudeshnaSur/Test.git (push)

Cloning and forking with hub

You may also clone and fork utilizing hub as a substitute of clicking-through to the GitHub GUI. I take pleasure in that hub routinely acknowledges the repository we’re focusing on so long as it has a namespace, then a slash, then the repository identify. So if we need to clone the supply code for hub itself, accessible at https://github.com/github/hub, we solely want to jot down:

$ hub clone github/hub
Cloning into 'hub'...
distant: Enumerating objects: 26, carried out.
distant: Counting objects: 100% (26/26), carried out.
distant: Compressing objects: 100% (22/22), carried out.
distant: Total 19712 (delta 7), reused 13 (delta four), pack-reused 19686
Receiving objects: 100% (19712/19712), 6.76 MiB | 7.25 MiB/s, carried out.
Resolving deltas: 100% (12912/12912), carried out.

Now I can do a traditional change to my copy of the repository. I’ll create a department referred to as subject, take a look at the department, then make a minor change and commit it (these are all normal Git instructions):

$ cd hub
$ git checkout -b subject
Switched to a brand new department 'subject'
$ echo “Hey” >test2.txt
$ git add .
$ git commit -m ‘Adding take a look at 2
[grasp cbb6fde5805a] Adding take a look at 2
 1 file modified, 1 insertion(+)
 create mode 100644 test2.txt

This clone is presently github/hub, which I would not have write entry to. But I can simply fork the repository and push modifications to it:

$ hub fork –remote-name origin

The output stories that your account is forking the unique repositories and all its branches. Note that you probably have have already got a distant named origin, hub will default to giving the brand new distant the identical identify as your username (if this terminology is complicated, read this refresher on remotes and forks). Next, let’s push the department, subject, to my fork:

$ git push origin subject

I can now open a pull request (PR) immediately from the command line by typing:

$ hub pull-request

This will open a textual content editor so I can add a PR message, and I can then handle the PR from there. I may even handle different PRs from the command line with the hub pr listing command.

Using different hub options

The story does not finish right here; hub gives many different options:

  • Check the continual integration (CI) standing for our branches:
    $ hub ci-status
  • Open a venture in your default net browser:
    $ hub browse github/quickstart
  • Synchronize all of your native branches to match the distant’s newest state:
    $ hub sync
  • List points assigned to your identify:
    $ hub challenge --assignee User_Name
  • List open points within the repository you might be in:

    $ hub challenge --limit 20
    [lists solely 20 points]

  • Open the present venture’s points web page:
    $ hub browse --issues
  • Check out a PR whereas reviewing a PR:
    $ hub pr checkout 123
  • Close a difficulty after merging:
    $ hub challenge replace 123 --state closed
  • Transfer challenge to a brand new repository:
    $ hub challenge switch 123 ANOTHER-REPO
  • Delete a repository in GitHub:
    $ hub-delete github/wiki-links

Hub is each useful and simple to make use of from the command line. If you are transitioning from the GUI to the command line and need to make that have extra intuitive, give hub a try.

Most Popular

To Top