GitHub from the command line with hub
Getting Started
Now that you have a working version of hub, I'll introduce you to some of the basic functions.
When you get started, you'll likely want to create a new repo on GitHub. To do that, navigate to any folder where you want to initialize Git:
$ cd Documents $ mkdir Test; cd Test/ $ git init Initialized empty Git repository in /Users/SudeshnaSur/Test/.git/
Hub has now initialized a GitHub repository for you, but at the moment, it's empty because Git only sees files that have recently been changed. So now, place any file inside your new repo, and add some text to it using echo
:
$ echo "Hello" > test.txt
Next, check the git status
, and you'll see that, as of right now, there are no commits:
$ git status On branch master No commits yet Untracked files: test.txt nothing added to commit but untracked files present
Next, run git add
:
$ git add .
By using this command, you have now staged the changes but not yet committed them. In order to commit the changes, you'll need a GitHub account. If you don't already have a GitHub account, you can create one using this step-by-step guide [5].
Now you need to tell your local version of Git to use your account, so you'll need to provide it with your account's username and email address. These details will be contained in every commit message you add to any repo, so that anyone else looking at the code can see that you are the author.
To add these details to your local version of Git, run the following:
git config --global user.email "email@example.com" git config --global user.name "Your Name"
If you're worried about sending your email out to everyone who has access to a particular repo, there are also ways of hiding it. There's a feature to allow you to hide your email address, or you can just set your email address to your GitHub email address, in order that other users only see your GitHub credentials [6].
So now that everything is linked up, you can begin to make commits. First, navigate to the location you were in before – and where you created a Git repo. Then run:
$ git commit -m 'Adding a test file' [master (root-commit) 07035c94e038] Adding a test file 1 file changed, 1 insertion(+) create mode 100644 test.txt $ git status On branch master nothing to commit, working tree clean
And that is all: You've now initialized a repo, made a change, and committed it. The change will appear in the repo against your email address. This is the basic process of working with hub, and you'll quickly see that it's far faster than working with the GitHub GUI directly.
Going Further
Up until this point, you've used hub to complete tasks that you could have done easily on the GitHub GUI. However, as just a little taste of the more advanced features of hub, I'll show you how to automatically create a new GitHub repo from the local system.
If you run hub create
, hub will automatically create a new repo on GitHub with the same name as the current directory on your local system:
$ hub create Updating origin https://github.com/YourRepo/Test
Even better, using the following command will even link your repository with the remote mirror:
$ git remote -v origin git@github.com:YourRepo/Test.git (fetch) origin git@github.com:YourRepo/Test.git (push)
Everyday Tasks
Most of the basic tasks that you use GitHub for can now be done straight from the command line. These tasks include cloning or creating repositories, browsing project pages, listing issues with repositories, or just staying up to date with projects you are following.
To clone a project, run:
$ hub clone project_name
To clone another project:
$ hub clone github/hub
To fast-forward all local branches to match the latest version on the project:
$ cd myproject $ hub sync
To list the latest issues in the current repository and limit the number of issues returned to 10:
$ hub issue --limit 10
To see all the issues of a repository on the project's issues page:
$ hub browse -- issues
« Previous 1 2 3 4 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.
-
HashiCorp Cofounder Unveils Ghostty, a Linux Terminal App
Ghostty is a new Linux terminal app that's fast, feature-rich, and offers a platform-native GUI while remaining cross-platform.
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.