Chapter 15: Setting up Github

Github is a powerful, advanced remote Git management tool. You should use this for personal projects as well as team projects.


What you will learn

  • Creating a Github Account
  • Generating an SSH Key
  • Adding an SSH Key to SSH-Agent
  • Adding SSH Key to Github account

Key Terms

  • Repository: a central location where data is stored and can be managed.
  • Github: an online Git management platform where code can be stored and managed.
  • SSH Key: a means of identifying yourself to an SSH server for the secure transferral of data.

In this chapter, we are going to learn how to set up Github – an amazing online Git management tool. It allows for individuals or teams to push, pull, merge, and manage their entire code base. You can create public or private repositories (great for companies working on new apps).

In the developer world, a Github profile can be equated with a portfolio of work. Therefore, it is paramount to build out a nice, beefy Github profile with all the projects you build throughout this book; Devslopes courses, or any other personal projects you want to post publicly.

Creating a Github account

First, open Safari or your browser of choice. Navigate to www.github.com and create an account by clicking the Sign Up button at the top of the page. Create an account and follow the steps necessary to activate your account.

Next up, we need to create an SSH key to identify your computer as a trusted device so that Github knows that all code is coming from a secure device. It works just like a key into a lock, but for your Github account.

Generating an SSH Key

On your Mac, go to Applications > Utilities and click on Terminal. Alternatively, you can press + Space and type terminal into Spotlight Search to find it. Upon opening, a new Terminal window should pop up.

We need to generate an SSH key for Github to use.

First, type the following but add in your Github email in place of the example email:

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Terminal will respond with the following:

Generating public/private rsa key pair.

Then Terminal will display:

Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

Press Enter to save it to the default locations it chooses.

The next prompt will ask you to create/verify a password to secure the SSH key. This is entirely optional and up to you if you'd like to do so.

Adding an SSH Key to SSH-Agent

Now that we have an SSH key, we need to check if ssh-agent is working and then add it to the SSH agent:

In Terminal, type the following:

$ eval "$(ssh-agent -s)"

Press Enter and a message should print below similar to this one: Agent pid 59566 Then type the following command:

$ ssh-add ~/.ssh/id_rsa

Adding SSH Key To Github Account

Now that we have created a secure SSH key and have added it to our SSH agent, we need to connect it with our Github account so that our Mac and Github can communicate.

In Terminal, type:

$ pbcopy < ~/.ssh/id_rsa.pub

This will copy our SSH key to our clipboard.

Return back to your web browser and click on your profile in the top right corner. In the following drop down menu, click Settings (Figure 1.15.1).

Figure 1.15.1

userbar-account-settings.png

On the side of the page, click SSH and GPG keys (Figure 1.15.2).

Figure 1.15.2

settings-sidebar-ssh-keys.png

Click New SSH key or Add SSH key to add our key that we have copied (Figure 1.15.3).

Figure 1.15.3 ssh-add-ssh-key.png

Type a descriptive title in the "Title" field (i.e. "Jerry's MacBook Air") and paste in your key to the "Key" field below (Figure 1.15.4).

Figure 1.15.4 ssh-key-paste.png

At the bottom of the page, click the Add SSH key button (Figure 1.15.5).

Figure 1.15.5

ssh-add-key.png

You may be required to enter your Github password to confirm making these changes.

Wrapping up

After following the steps in this chapter, you are now ready to learn how to use Github. In the next chapter, we will talk about local and remote code repositories and how to push our local code to Github for storage and management.