DEV Community

Daniel Kemei
Daniel Kemei

Posted on

Getting Started with Git and GitHub

What is Version Control?

Version Control is a system that tracks and manages changes to your code over time. This lets you:

  • Track who made what changes and when

  • Revert to previous versions of your project

  • Collaborate with others
    Git is the most popular version control system.
    GitHub on the other hand is a platform where you can store and share your Git repositories online.A repository Is a place where all versions of your files and their complete change history are stored.
    Think of Git like your personal diaries where you write entries and Github like the library where you share your diaries with others

Step 1: Introduce Yourself to Git

Before you start using Git, you need to configure it with your identity which will be attached to every change you make.

Set Your Username

git config --global user.name "yourname"
Enter fullscreen mode Exit fullscreen mode

Set Your Email

git config --global user.email "youremail@gmail.com"
Enter fullscreen mode Exit fullscreen mode

Important: Use the same email address that you'll use for your GitHub account.

Verify Your Configuration

To confirm everything is set up correctly, run:

git config --global --list
Enter fullscreen mode Exit fullscreen mode

This command will display your configured username and email.

Step 2: Connect Git to GitHub Using SSH

SSH (Secure Shell) provides a secure way to connect your computer to GitHub without typing your password every time.

Generate Your SSH Key

Run this command to create a new SSH key pair:

ssh-keygen -t ed25519 -C "youremail@gmail.com"
Enter fullscreen mode Exit fullscreen mode

What this does: Generates a public/private key pair using the ed25519 encryption algorithm.
When prompted:
Path to save the key: Press Enter to accept the default location
Passphrase: You can press Enter to skip, or add a password for extra security

Start the SSH Agent

The SSH agent is a program that holds your private keys in memory. Start it with:

eval "$(ssh-agent -s)"
Enter fullscreen mode Exit fullscreen mode

You should see output like Agent pid 12345, confirming the agent is running.

Add Your Key to the SSH Agent

ssh-add ~/.ssh/id_ed25519
Enter fullscreen mode Exit fullscreen mode

This adds your newly generated private key to the agent so it can be used for authentication.

Copy Your Public Key

To view and copy your public key, run:

cat ~/.ssh/id_ed25519.pub
Enter fullscreen mode Exit fullscreen mode

This will display your public key. Copy the entire output.

Step 3: Add Your SSH Key to GitHub

Now you need to tell GitHub about your SSH key:

Go to GitHub.com and sign in
Click your profile picture (top right) → Settings
In the left sidebar, click SSH and GPG keys
Click the New SSH key button
Give your key a descriptive title (e.g., "My Laptop")
Paste your public key into the "Key" field
Click Add SSH key

Test Your Connection

Verify everything is working:

ssh -T git@github.com
Enter fullscreen mode Exit fullscreen mode

If successful, you'll see a message like: Hi username! You've successfully authenticated...

Step 4: Create Your First Repository

You can create a repository locally on your computer or on GitHub.

Option A: Create a New Repository on GitHub

Go to GitHub.com and sign in
Click the + icon in the top right → New repository
Give your repository a name
Add a description
Choose Public or Private
Check "Add a README file"
Click Create repository

Option B: Create a Local Repository

Navigate to your project folder and initialize Git:

bashcd /path/to/your/project
git init
Enter fullscreen mode Exit fullscreen mode

This creates a hidden .git folder that tracks all your changes.

Step 5: Track Changes with Git

Git tracks changes in three stages: Working Directory → Staging Area → Repository.

Check the Status of Your Files

See which files have been modified:

git status
Enter fullscreen mode Exit fullscreen mode

This shows you:

  • Files that have been changed

  • Files that are staged (ready to commit)

  • Files that are untracked (new files Git doesn't know about)

Add Files to the Staging Area

Before Git can save your changes, you need to stage them:

# Add a specific file
git add filename.txt

### Add all changed files
git add .

# Add multiple specific files
git add file1.txt file2.txt file3.txt
Enter fullscreen mode Exit fullscreen mode

Commit Your Changes

A commit is a snapshot of your project at a specific point in time. Each commit has a message describing what changed.

git commit -m "Add initial project files"
Enter fullscreen mode Exit fullscreen mode

View Your Commit History

See all the commits you've made:

git log
Enter fullscreen mode Exit fullscreen mode

Step 6: Push Your Code to GitHub

Pushing means sending your local commits to GitHub so others can see them.

Push for the First Time

git push -u origin main
Enter fullscreen mode Exit fullscreen mode

Push Subsequent Changes

After the first push, you can simply use:

git push
Enter fullscreen mode Exit fullscreen mode

Step 7: Pull Changes from GitHub

Pulling means downloading changes from GitHub to your local computer.

Pull the Latest Changes

git pull
Enter fullscreen mode Exit fullscreen mode

This downloads and merges changes from GitHub into your local repository.

Top comments (0)