Git Basics
Your First Steps into Version Control
Ever accidentally deleted hours of code? Or wanted to go back to a previous version of your project but couldn't? That's where Git comes in.
What is Git?
Git is a distributed version control system that tracks changes in your code. Think of it as a time machine for your projects—you can save snapshots of your work, experiment without fear, and collaborate with others without chaos.
Created by Linus Torvalds in 2005, Git has become the backbone of modern software development.
Why Developers Love Git
Track every change: See who changed what, when, and why
Experiment safely: Try new features without breaking your working code
Collaborate easily: Multiple developers can work on the same project simultaneously
Rewind time: Messed up? Just roll back to a previous version
Work offline: Git works locally, no internet required
Core Concepts You Need to Know
Repository (Repo)
A folder that Git is tracking. It contains all your project files plus a hidden .git folder where Git stores its magic.
Commit
A snapshot of your project at a specific point in time. Think of it as a save point in a video game.
Branch
A separate line of development. The default branch is usually called main or master. Branches let you work on features without affecting the main codebase.
HEAD
A pointer that tells Git which commit you're currently looking at. It usually points to the latest commit on your current branch.
Staging Area
A middle ground between your working files and the repository. You choose which changes to include in your next commit.
The Git Workflow Visualized
Working Directory → Staging Area → Repository
(edit files) → (git add) → (git commit)
Essential Git Commands
Let's walk through a real workflow:
1. Initialize a Repository
git init
Transforms your current folder into a Git repository.
2. Check Status
git status
Shows which files have changed and what's staged for commit. This is your best friend—use it often!
3. Stage Files
git add filename.txt # Stage a specific file
git add . # Stage all changes
Moves changes to the staging area, preparing them for a commit.
4. Commit Changes
git commit -m "Add login feature"
Creates a snapshot with a descriptive message. Write clear messages—your future self will thank you!
5. View History
git log # Full history
git log --oneline # Compact view
Shows your commit history so you can see what happened when.
6. Create and Switch Branches
git branch feature-navbar # Create a new branch
git checkout feature-navbar # Switch to it
# Or do both at once:
git checkout -b feature-navbar
7. Merge Branches
git checkout main
git merge feature-navbar
Brings changes from one branch into another.
8. Clone a Repository
git clone https://github.com/username/repo.git
Downloads a complete copy of a remote repository to your machine.
A Beginner's Workflow Example
Let's say you're building a website:
# Start tracking your project
git init
# Check what's happening
git status
# Create your first HTML file
echo "<h1>Hello Git!</h1>" > index.html
# Stage it
git add index.html
# Commit it
git commit -m "Create initial homepage"
# Make changes
echo "<p>Welcome to my site</p>" >> index.html
# See what changed
git status
# Stage and commit again
git add index.html
git commit -m "Add welcome message"
# View your history
git log --oneline
Quick Reference Cheatsheet
| Command | What It Does |
git init | Start tracking a project |
git status | See current state |
git add <file> | Stage specific files |
git add . | Stage everything |
git commit -m "message" | Save a snapshot |
git log | View history |
git branch | List branches |
git checkout -b <name> | Create and switch to branch |
git merge <branch> | Combine branches |
Commit History Flow

Each letter represents a commit. You can branch off, work independently, then merge back.
Pro Tips for Beginners
Commit often: Small, focused commits are better than giant ones
Write clear messages: "Fix bug" is bad, "Fix login button alignment" is good
Use branches: Keep your main branch stable
Check status frequently: Before and after every operation
Don't panic: Git is very forgiving—most mistakes can be undone
What's Next?
You've now got the foundation! From here, explore:
Remote repositories (GitHub, GitLab)
Collaboration workflows (pull requests)
Advanced commands (rebase, stash, cherry-pick)
But for now, start practicing these basics. Create a test project, make some commits, create branches, and experiment. The more you use Git, the more natural it becomes.
Happy coding!