8. Git Configuration

8. Git Configuration

Day 4: Setting up Git and SSH

Note: I am a student, with zero coding or IT experience. These notes are based on my current level of understanding. Please do your own due diligence when working on this subject matter.

I worked on 3 things today:

  1. A GitHub account

  2. Git Configuration

  3. Configure SSH access to GitHub

GIT HUB

GitHub is a Microsoft company and is immensely popular with coders.

It's a place on the cloud that tracks your version history on Git. This means it keeps a record of all your code changes and the different versions of your projects, along with a whole lot of other things.

There are competitors like Mercurial, BitBucket, etc but by far GitHub is the most popular. As of January 2023, GitHub reported having over 100 million developers on it!

I am not sure why I had set up one, but I had a Git Hub account already! So, that was all done.

If you need an account, you can set one up here: github.com

GIT

As per Wikipedia, "Git tracks changes in any set of computer files, usually used for coordinating work among programmers who are collaboratively developing source code during software development."

So, GitHub is a service/platform that is built around Git, so that Git is "presented" in a more user-friendly graphic interface sort of way, and also allows the building of a community.

Git Configuration

This configuration happens on your local machine, and it's done so that our "gits" are stored in GitHub.

  1. Provide the username. Go to your Terminal and type in:
    git config --global user.name "your github username"

  2. Provide the email address:
    git config --global user.email "your github email address"

That's it.

You can check if it's configured correctly by typing:
ls .gitconfig
cat .gitconfig

Executing the above will list your username and email address you provided before. If you get that, it's all good. If stuck, this documentation from Atlassian is helpful.

GENERATING A NEW SSH KEY

This is an important step. You need to generate a new SSH (Secure Shell Protocol) key which keeps your account on your computer safe. You will also need to create a passphrases for additional security. Once these are set up, you don't need to provide your GitHub username and password each time.

More info here:

Generating a new SSH key:
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

Info on Passphrases:
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/working-with-ssh-key-passphrases

Step 1: In terminal:
ssh-keygen -C "your github email"

Step 2: Click enter when it asks you where you want to save it.

Step 3: Enter your passphrase twice (first entry and then confirmation)

Adding your SSH key to the ssh-agent

Step 4: In Terminal, start the ssh-agent:
eval "$(ssh-agent -s)"

Step 5: Add your SSH private key into ssh-agent:
ssh add ~/.ssh/id_rsa

Step 6: Enter the passphrase you created before

Step 7: Now, we need to add the details over to GitHub. Type in Terminal:
cat .ssh/id_rsa.pub

Step 8: Copy the entire long string (running into 4 lines). So, start from ssh-rsa and finish up after the email id.

Adding the string in to GitHub

Step 9: Login to GitHub.

Step 10: Go to Settings > SSH and GPG keys (seen on the left menu)

Step 11: Click on NEW SSH KEY button

Step 12: Give it some name like, "secure key macbook". It can be anything you want and helps you identify why you set this up.

Step 13: I left the Key Type as "Authentication Key".

Step 14: Paste the entire string you copied in Step 8 into the Key box.

Step 15: Click on Add SSH Key

That's it, folks. I am told that's all I have to do for now. If you have more info on this topic, please comment and let me know.