DEV Community

Cover image for Git & GitHub for Beginners: A Simple Guide to Version Control
Samuel Wachira
Samuel Wachira

Posted on

Git & GitHub for Beginners: A Simple Guide to Version Control

If you are learning programming, sooner or later you will hear about Git and GitHub. At first, they may sound confusing but once you understand the basics, they become essential tools in every developer’s workflow.

In this article, you will learn:

  • What Git is and why version control matters
  • How to push code to GitHub
  • How to pull code from GitHub
  • How to track changes using Git

Let’s go step by step.

What is Git?

Git is a version control system.
It helps you track changes in your code over time.

Think of Git like a time machine for your project:

  • You can save versions of your code
  • Go back to previous versions if something breaks
  • See who changed what and when
  • Work with other developers without overwriting each other’s work Git runs locally on your computer.

Why Version Control is Important

Imagine this situation:

  • You are working on a project.
  • You make changes.
  • Suddenly, your code stops working.
  • You wish you could go back to yesterday’s working version.

Without version control:

  • You would have to manually copy folders.
  • You might lose working code.
  • Collaboration becomes messy.

With Git:

  • Every saved version is stored safely
  • You can experiment without fear
  • Teams can work together smoothly

That is why version control is essential in real-world development.

What is GitHub?

GitHub is an online platform that stores Git repositories.

  • Git - tool on your computer
  • GitHub - cloud storage for your Git projects

It allows:

  • Backup of your projects online
  • Sharing code with others
  • Collaboration on open-source projects

Installing Git

Download Git from:
https://git-scm.com/

After installation, verify:

git --version

Enter fullscreen mode Exit fullscreen mode

Basic Git Setup

Before using Git, set your username and email:

git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
Enter fullscreen mode Exit fullscreen mode

How to Track Changes Using Git

Step 1: Initialize Git in your project

Inside your project folder:

git init
Enter fullscreen mode Exit fullscreen mode

This creates a hidden .git folder — your local repository.

Step 2: Check file status

git status
Enter fullscreen mode Exit fullscreen mode

This shows:

  • Which files are new
  • Which files were modified
  • Which files are ready to commit

Step 3: Add files to staging

To track a file:

git add filename
Enter fullscreen mode Exit fullscreen mode

Or add everything:

git add .
Enter fullscreen mode Exit fullscreen mode

Step 4: Commit changes

A commit saves a snapshot of your project.

git commit -m "Added homepage layout"
Enter fullscreen mode Exit fullscreen mode

Each commit has:

  • A unique ID
  • A message describing the change

Step 5: View commit history

git log
Enter fullscreen mode Exit fullscreen mode

How to Push Code to GitHub

Step 1: Create a repository on GitHub

Step 2: Connect local Git to GitHub

Copy the repository URL from GitHub, then run:

git remote add origin https://github.com/yourusername/your-repo.git
Enter fullscreen mode Exit fullscreen mode

Step 3: Push your code

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

Now your project is uploaded to GitHub 🎉

How to Pull Code from GitHub

If you want to download updates from GitHub to your computer:

git pull origin main
Enter fullscreen mode Exit fullscreen mode

This fetches the latest changes and merges them into your local project.

Bonus: Cloning a GitHub Repository

If a project already exists on GitHub, you can copy it to your computer:

git clone https://github.com/username/repository.git
Enter fullscreen mode Exit fullscreen mode

Common Git Workflow

  1. Make changes to code
  2. git status
  3. git add .
  4. git commit -m "message"
  5. git push

Repeat 🚀

Final Thoughts

Git and GitHub may seem complex at first, but once you practice the basic commands, they become second nature.
They help you:

  • Keep your code safe
  • Work confidently
  • Collaborate professionally If you are serious about software development, mastering Git is a must.

Quick Command Summary

git init
git status
git add .
git commit -m "message"
git push
git pull
git clone
git log
Enter fullscreen mode Exit fullscreen mode

Top comments (0)