Skip to content

Latest commit

 

History

History
127 lines (110 loc) · 3.61 KB

Setting-Up-Git-and-GitHub.md

File metadata and controls

127 lines (110 loc) · 3.61 KB

Setting Up Git and GitHub

Prerequisites

  • Basic understanding of command-line interface (CLI).
  • A GitHub account (sign up at GitHub).

Step 1: Installing Git

  1. Windows:

    • Download the installer from git-scm.com.
    • Run the installer and follow the prompts.
    • Open Git Bash (installed with Git) to use Git commands.
  2. Mac:

    • Open the Terminal.
    • Install Homebrew if not already installed:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
    • Install Git:
    brew install git
    
  3. Linux:

    • Use the package manager specific to your distribution.
    • For Debian/Ubuntu:
    sudo apt-get install git
    
    • For Fedora:
    sudo dnf install git
    

Step 2: Configure Git (Using bash)

Set your username and email in Git:

git config --global user.name "Your Name"
git config --global user.email "[email protected]"

Step 3: Generate SSH Keys

SSH keys allow you to securely connect to GitHub without needing to enter your username and password each time.

  1. Generate a new SSH key:

    • Open your terminal (or Git Bash on Windows).
    • Generate the SSH key:
      ssh-keygen -t ed25519 -C "[email protected]"
    • When prompted, accept the default file location and enter a passphrase for added security.

    If you're using an older system that doesn't support ed25519, use rsa instead:

    ssh-keygen -t rsa -b 4096 -C "[email protected]"

Step 4: Add the SSH Key to GitHub

  1. Copy the SSH key to your clipboard:

    • On Linux or Mac:
      cat ~/.ssh/id_ed25519.pub | pbcopy
      For rsa:
      cat ~/.ssh/id_rsa.pub | pbcopy
    • On Windows (Git Bash):
      clip < ~/.ssh/id_ed25519.pub
      For rsa:
      clip < ~/.ssh/id_rsa.pub
  2. Add the SSH key to your GitHub account:

    • Go to GitHub and log in.
    • In the upper-right corner, click on your profile photo, then click Settings.
    • In the user settings sidebar, click SSH and GPG keys.
    • Click New SSH key.
    • Provide a descriptive title for the new key and paste your SSH key into the "Key" field.
    • Click Add SSH key.

Step 5: Test the SSH Connection

To ensure everything is set up correctly, test the connection to GitHub:

You should see a message like this:

Hi yourusername! You've successfully authenticated, but GitHub does not provide shell access.

Step 6: Clone a Repository

Now that your laptop is connected to GitHub via SSH, you can clone repositories:

  1. Navigate to the directory where you want to clone the repository:

    cd /path/to/your/directory
  2. Clone the repository using SSH:

    • Go to the repository page on GitHub.
    • Click the green Code button, select SSH, and copy the SSH URL.
    • Clone the repository:
      git clone [email protected]:username/repository.git

Summary

You’ve successfully connected your laptop with GitHub using SSH. You can now clone repositories, push changes, and collaborate securely without entering your credentials each time.