Git for Beginners: Visual Version Control

Master the basics of Git: commits, repositories, branches, and merging. A visual guide for absolute beginners.

Git for Beginners: Visual Version Control
📧

Get weekly IT guides

Join 5,000+ IT professionals

Subscribe Free

Have you ever saved a file as final.txt, then final_v2.txt, then final_REAL_v3.txt? Imagine doing that with code, but you can travel back in time to any version instantly, and multiple people can work on the same file without overwriting each other. That’s Git.

Introduction

Git is a Version Control System (VCS). It tracks changes to files over time. It is the industry standard tool for programmers. You simply cannot get a job in tech without knowing Git.

Git vs. GitHub - The Difference
  • Git: The tool installed on your laptop that tracks changes. (Like MS Word)
  • GitHub: A website that hosts your Git repositories in the cloud. (Like Google Drive/Dropbox for code)
Mental Model: The Save Game System

Think of Git like a video game save system:

  • Commit = Creating a “Save Point”.
  • Message = Naming the save (“Before Boss Fight”).
  • Checkout = Loading an old save.
  • Branch = A parallel timeline where you try something risky. If you die, your main game is safe.

The 3-Stage Workflow

Git adds a step between “Working” and “Saving”. It’s called Staging.

  1. Working Directory: Where you edit files.
  2. Staging Area: Where you pick which files you want to save.
  3. Repository (.git): Where the snapshots are stored forever.
Diagram showing movement of files from working dir to staging to repo
The Git Lifecycle: Modify → Stage (add) → Commit.

Essential Commands

1. Setup (Do this once)

Tell Git who you are. This name will appear on your commits.

git config --global user.name "Your Name"

Set your username

beginner
git config --global user.email "you@example.com"

Set your email

beginner

2. Start a Repository

Turn a folder into a Git repository.

git init

Initialize a new repo in the current folder

beginner

3. Save Changes (The Daily Loop)

Step A: Check Status

git status

See which files have changed

beginner

Step B: Stage Files

git add index.html

Add specific file to staging

beginner
git add .

Add ALL changed files to staging

beginner

Step C: Commit (Save Point)

git commit -m "Added navigation bar"

Save staged changes with a message

beginner

4. History

git log

View commit history (press Q to exit)

beginner

Branching and Merging

Branching lets you duplicate your code to work on a new feature (like “Dark Mode”) without breaking the working version (“Main”).

Git branching and merging flow diagram
Branching creates a parallel timeline. Merging brings it back.

Create and Switch

git branch

List all branches

beginner
git checkout -b new-feature

Create AND switch to a new branch called 'new-feature'

beginner
git switch main

Go back to the main branch

beginner

Merge (Combine)

Once your feature works, you merge it back into main.

  1. Switch to main: git switch main
  2. Merge the feature: git merge new-feature

Working with GitHub (Remote)

To copy your code to the cloud:

  1. Create a New Repository on GitHub.com.
  2. Connect your local folder to it:
git remote add origin https://github.com/user/repo.git

Link local repo to GitHub URL

beginner
  1. Upload (Push):
git push -u origin main

Upload your commits to GitHub

beginner
  1. Download (Clone):
git clone https://github.com/user/repo.git

Download a repo from GitHub to your computer

beginner

Hands-On Challenge

  1. Create a folder git-demo and run git init.
  2. Create a file hello.txt, add text, and save.
  3. Run git status. See it in red?
  4. Run git add . then git commit -m "First commit".
  5. Create a branch: git checkout -b experiment.
  6. Edit the file. Commit.
  7. Switch back (git switch main). Notice your edit is gone!
  8. Merge it: git merge experiment. Your edit is back.

Key Takeaways

  • git init starts tracking a folder.
  • git add . moves changes to the staging area.
  • git commit -m “msg” saves the snapshot permanently.
  • git branch lets you work safely in isolation.
  • git push sends your code to GitHub.
🧠

Test Your Knowledge

Take a quick 5-question quiz to check your understanding.


Key Takeaways

  1. git init — Start tracking any folder as a Git repository.
  2. git add . — Stage all changed files before saving.
  3. git commit -m "msg" — Save a permanent snapshot with a message.
  4. git branch / git checkout -b — Work safely in an isolated parallel timeline.
  5. git push — Upload your work to GitHub for backup and collaboration.
You Now Know

You have the complete Git survival kit. You can init, commit, branch, merge, and push to GitHub. Every developer on earth uses exactly these same commands, every single day.

Next Steps

Found this helpful? Explore more in the Tools Hub!

📧

Get weekly IT guides

Join 5,000+ IT professionals

Subscribe Free
Type to start searching...