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
-
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.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.