GitHub is a web-based platform that enables users to manage and collaborate on code repositories. Today, we will talk about using GitHub and how to get started. Let’s look at the following topics:

  1. Adding an SSH key to GitHub
  2. Configuring your Git username and email
  3. Initializing (or Cloning) a Git repository

Let’s get started!

Adding an SSH Key to GitHub

The first step in working with GitHub is to add an SSH key to your account. This key will allow you to securely connect to the GitHub servers without entering your username and password every time.

  1. Open your terminal and navigate to the directory where your SSH key is stored. For example, the key may be located at /home/username/.ssh/id_rsa.pub.
  2. Copy the contents of the key file, for example, after running the command cat /home/username/.ssh/id_rsa.pub.
  3. Log in to your GitHub account and go to the Settings page. From there, click on “SSH and GPG keys” on the left-hand side.
  4. Click on the “New SSH key” button and give your key a title (e.g. “My SSH key”). Paste the contents of your key file into the “Key” field and click “Add SSH key”.

Configuring Your Git Username and Email

The final step is to configure your Git username and email. This information is used to identify the author of each commit. Here’s how to configure your Git username and email:

  1. Open your terminal and run the command git config --global user.name USERNAME. Replace “USERNAME” with your username.
  2. Run the command git config --global user.email youremail@domain.com. Replace “youremail@domain.com” with your email address that you have used to create your GitHub account.

Initializing (or Cloning) a Git Repository

The next step is to initialize a Git repository on your local machine. A Git repository is a place where you store and manage your code. Here’s how to initialize a Git repository:

  1. Option-1: Create a new Git repository.
    Open your terminal and navigate to the directory where you want to create your repository. Run the command git init. This will create a new Git repository in the current directory.
    Option-2: Clone a Git repository
    Let’s assume that you have forked a repository on your GitHub account. Open your terminal and navigate to the directory where you want to clone the repository locally. Type git clone git@github.com:username/repository.git
    You can check the content by typing cd repository. You can get the exact address of the repository by clicking the <>Code tab on the repository’s page.
  2. Suppose you have created a file in this repository directory; you can add your files to the repository by running the command git add . to add all files in the current directory to the repository. You can also add a single file using the command git add filename
  3. Commit your changes by running the command git commit -m "Some comments for your commit". This will create a new commit with a message.

And there you have it! You now know how to add an SSH key to GitHub, configure your Git username and email, and initialize/clone a Git repository. With these basics in place, you’re ready to start managing your code on GitHub.