DEV Community

Judy Mokaya
Judy Mokaya

Posted on

Git & GitHub: A Beginner’s Step-by-Step Guide to Version Control

Introduction

If you’re new to software development, you may have heard of Git and GitHub, but wondered what they actually do.

This guide explains Git in simple terms, why version control is important, and how to push, pull, and track your code on GitHub — all step by step.


What Is Git?

Git is a version control system. It keeps track of changes in your code over time.

Instead of manually saving multiple copies like project_v1, project_v2, etc., Git stores every change in a history. You can go back to any previous version anytime.


Why Version Control Is Important

Version control helps you:

  • Track changes in your code
  • Collaborate with other developers without overwriting work
  • Recover mistakes easily
  • Maintain a history of your project

Git makes development faster, safer, and more organized.


What Is GitHub?

GitHub is an online platform that stores Git repositories.

It allows you to:

  • Back up your code online
  • Share code with others
  • Collaborate on projects
  • Access your projects from anywhere

Think of Git as the tool to manage versions, and GitHub as the cloud storage for your Git projects.


How to Push Code to GitHub

Initialize Git in your project
Inside your project folder, run:

git init
Enter fullscreen mode Exit fullscreen mode

This sets up Git in your project so you can start tracking changes.

Check File Status

git status
Enter fullscreen mode Exit fullscreen mode

This shows:

  • Untracked files

  • Modified files

  • Files ready to commit

Add Files to Track
Add all your files to Git staging:

git add .
Enter fullscreen mode Exit fullscreen mode

Or add a specific file:

git add filename
Enter fullscreen mode Exit fullscreen mode

Commit Changes
Save a snapshot of your current work:

git commit -m "Initial commit"
Enter fullscreen mode Exit fullscreen mode

Always use a clear, descriptive message for your commits

Connect to Your GitHub Repository
Create a repository on GitHub (do not initialize with README) and then run:

git remote add origin git@github.com:username/repository-name.git
Enter fullscreen mode Exit fullscreen mode
  • Replace username with your GitHub username

  • Replace repository-name with your repository name

Push Code to GitHub
Send your local commits to GitHub:

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

Check GitHub — your files should now appear online

How to Pull Code from GitHub

If you or someone else updates the repository, pull changes to your local machine:

git pull origin main
Enter fullscreen mode Exit fullscreen mode

This keeps your local project synced with GitHub.

How to Track Changes Using Git

Check Status

git status
Enter fullscreen mode Exit fullscreen mode

See which files have changes or are untracked.

View Commit History

git log
Enter fullscreen mode Exit fullscreen mode

Shows all commits, authors, dates, and messages.

Typical Git Workflow

  1. Make changes to files

  2. git status → check changes

  3. git add . → stage changes

  4. git commit -m "Message" → commit changes

  5. git push → upload to GitHub

Repeat this cycle whenever you work on your project.

Important Note for macOS Users

Git Bash is mainly used on Windows. On macOS (and Linux), you can use Terminal, which supports the same Git commands.

Conclusion

Git and GitHub are powerful tools for anyone working with files that change over time — not just developers.

They help you:

  • Organize projects
  • Collaborate easily with others
  • Keep your work safe from mistakes

Whether you’re coding, writing, designing, or managing any project, learning Git will make your workflow smoother and more reliable. Start practicing today and take control of your work history!

Top comments (0)