Git & Hub: A New Path of Code Sharing

Hello guys, how are you? I hope you’re all doing fine!

In this article we will cover two excellent tools: Git and Hub. Git we all know and love, it has been there for a long time.

Hub, on the other hand, is quite recent and has not yet earned its spot in the mainstream.

First, let's start with Git. For those who don't know this fantastic tool, there is a great opportunity to learn it.

The History and Usability of Git

In the year of 1991, the Linux Kernel started been developed. From the beginning, the developers realized the problem of working in a distributed environment. Soon they became aware of BitKeeper's issues. Their distributed version control software wasn't able to handle their needs. So they started developing their own.

Linus Torvalds, the creator of the Linux Kernel, use his experience to create a new tool, which is now known as Git.

Git is a distributed version control tool, based on several principles:

  • speed

Let us see what Git is capable of doing:

Versioning files

With Git we can create repositories in order to keep a track of what changes we made in our code. There is a small example below:

how to initiate a local repository

Like the above, we create a repository, using the git init command and then we add a file with some content inside.

In order to create a change, we make a commit. Essentially is a package with all changes made in our code. We can see what will be committed with the git status command.

We must add which files we want in a single commit, we can add them individually, like git add test.txt or we could add everything that showed up in the git status , using the command git add --all .

With everything added to our commit, we effectively make a commit. Then we can check if we have new changes pending. With every commit, we should leave a message telling what changes we made to the code, that’s why the parameter -m .

code commit

Cool. What do we do next? We have to upload it. Until now, our changes are in our own machines, we have to create a remote repository, and for this, we are going to use GitHub.

How to use remote repositories

Go to their website and click on Sign Up. Create an account, filling the form, just like I did:

creating GitHub account

You can select the Free Plan, it’s alright. After the verification, and proper login, create a new repository by clicking in the button ‘New’ in the image below:

creating a new repository

Now, choose a name for you repository and leave it as public. It works if it is private too, but for now, public is the way to go.

Don’t add a README file, we are not going to use it. Click on ‘Create repository’.

You will see a screen like this:

first look of our repository

Right now, our local repository and our GitHub repository are not in sync.

And since we already have a repository, we are going to use those commands to sync them:

git remote add origin
git push -u origin master

So let’s jump into our terminal and run them:

push our changes

If we refresh our GitHub page:

repository sync

OK, great! We now have our file and we created a new repository. But wait… Is there another way to do this?

Using Hub: Our new tool to interact with GitHub

GitHub has been around for quite some time. It was launched at 2008, when Git had already dominated the versioning market. As soon as GitHub was discovered for the majority of projects, soon the open source products begun to grow.

Thanks to GitHub now minor programmers could show up their projects and ideas and get contributors from all around the globe.

Microsoft buys GitHub

And on June 4, 2018, Microsoft announced they would be buying GitHub for merely 7.5 Billion USD. And here is a quote from one of the CEOs from GitHub:

“I’m extremely proud of what GitHub and our community have accomplished over the past decade, and I can’t wait to see what lies ahead. The future of software development is bright, and I’m thrilled to be joining forces with Microsoft to help make it a reality. Their focus on developers lines up perfectly with our own, and their scale, tools and global cloud will play a huge role in making GitHub even more valuable for developers everywhere.”

Now, Microsoft has taken another great step. They’ve created an command line interface(CLI) to interact with GitHub.

Let’s get our hands dirty!

Installing and first steps

Go to the official GitHub page. There are a few steps to install it, I’ll install on Windows and Linux.

In order to install on Windows, first download the Chocolatey Package Manager, here is a link and a guide to do it. After that, open a terminal window with administrator privileges and run:

choco install hub
choco install hub

The same can be done with Linux

apt install hub
sudo apt install hub -y

After a few seconds the installation will finish and you can check if everything is correct by running:

hub version

Now, add it to your profile. On Windows add it to your profile.ps1 file or run:

Set-Alias git hub
Add-Content $PROFILE "`nSet-Alias git hub"

On Linux add to your .bash_profile:

eval "$(hub alias -s)"

Before we begin, let’s add an environment variable, if you like. If you are on Linux, add this line to your .bashrc file:

export GIT_EDITOR=vim

and then use a source ~/.bashrc

If you are on Windows, click on This PC using the right button and go to Properties. Go to Advanced Configuration and then Environment Variables. Add to the system level the following:

add env var

This will make you hub use vim instead of nano. If you prefer nano, don’t do it.

Now, we are going to see some concepts related to remote Git repositories and how to interact with them using the command line.

Interacting with GitHub

With Hub we have multiple ways to interact with GitHub. Let’s us see some of them:

We can clone repositories:

hub clone mschirbel/fat-birdy
hub clone repositories

Here I’m cloning my own repository, in this case I could have omitted the mschirbel username in the command.

I can also create my on repository:

creating repositories
mkdir Github
git init
hub create

Did you see how easy it was? You can go ahead and check your GitHub. It is there. If you were prompted with some username and password, that is a one-time entry, don’t worry.

And we have many other functionalities embedded in this CLI. Now, let’s check how can we contribute to open source projects, which are hosted on GitHub.

I went ahead and created some issues on my own repository:

issues on my repository

Let us use Hub to check them:

hub clone Github
cd Github
hub issue
hub issue show 2
showing issues

Ok. Now let’s see how we can make a Pull Request

git checkout -b pr
echo "OLA MEDIUM" >
git add .
git commit -m "ola medium"
git push origin pr
hub pull-request
making a pr

We can check it is there:

check our new pr

If you want, check your pull request using:

hub pr list
hub pr show <NUMBER>

This will open your browser.

If you want to merge this pull request:

hub merge <URL>

That is what I wanted to show for you guys, if you liked this article please go ahead and try for yourself this amazing tool, you won’t regret it.

I really hope you enjoyed this tutorial. If you have any questions, please leave a comment or send me a message on my LinkedIn.

See ya!

This is just a bit of my life. Writing another line everyday!