← Back to all guides

Git: Your Code's Time Machine

Git saves snapshots of your code so you can always go back if you mess up. Here's how to use it without crying.

Terminalbeginner8 min read

Git: Your Code's Time Machine

You know that feeling when you're working on something and you accidentally delete everything? Or you make a bunch of changes and suddenly nothing works and you have no idea what you broke? Git fixes that. It's a time machine for your code.

Why Git Is Non-Negotiable

This isn't optional. If you code, you use Git. Here's why:

  • Undo anything: Accidentally deleted a file you spent 3 hours on? Git can bring it back in one command. Changed something that broke everything? Roll back to when it worked.
  • Collaboration: Every team uses Git. When you and a coworker both edit the same project, Git intelligently merges your changes together. No emailing files back and forth, no "final_v3_REAL_FINAL.js."
  • Your portfolio: GitHub (which runs on Git) is where you showcase your code to potential employers. It's like a resume that actually proves you can build things.
  • Freelancing and open source: Want to contribute to an open-source project? Git. Want to hand off code to a client? Git. Want to collaborate with another developer across the world? Git.
  • Job interviews: "Do you use Git?" is not even a question anymore — it's assumed. Not knowing Git is like applying for an office job and not knowing email.
  • Deploying websites: Services like Vercel and Netlify deploy your site automatically every time you push code to Git. Push to GitHub, site updates in 60 seconds.

Every single developer, from beginners to senior engineers at Google, uses Git daily. Learning it now saves you from a world of pain later.

What Is Git?

Git takes snapshots of your code at specific moments. Each snapshot is called a "commit." If you ever mess something up, you can go back to any previous snapshot.

Think of it like saving your game in a video game. You save at certain checkpoints, and if your character dies, you load the last save.

💬 Denise says

Before I learned Git, I used to make copies of my folders like "my-project-v2", "my-project-v2-final", "my-project-v2-final-ACTUALLY-FINAL." We've all been there. Git is the grown-up version of that, and it's SO much better.

Setting Up Git

First, install Git (it's probably already installed). Then tell it who you are:

1# Check if Git is installed:
2git --version
3
4# Tell Git your name and email (one-time setup):
5git config --global user.name 'Denise'
6git config --global user.email 'hello@techwithdenise.com'
7
8# Start tracking a project:
9cd my-project
10git init
11# That's it! Git is now watching this folder.

The Three Steps of Saving

Git has a three-step save process. It sounds extra, but it gives you control over exactly what you save:

1# Step 1: Check what changed
2git status
3# Shows you which files were modified, added, or deleted
4
5# Step 2: Stage the changes you want to save
6git add index.html
7git add style.css
8# Or add everything at once:
9git add .
10
11# Step 3: Save the snapshot with a message
12git commit -m 'Added navbar and styled the homepage'

A Visual Walkthrough

1Your project timeline:
2
3Commit 1 Commit 2 Commit 3
4'Initial setup' 'Added navbar' 'Styled homepage'
5[Save #1] ───→ [Save #2] ───→ [Save #3] ← YOU ARE HERE
6
7Oh no! The homepage looks terrible now!
8
9You can go back to Commit 2:
10git checkout [commit-2-id]
11
12Or just see what changed:
13git diff
14
15Or undo the last commit entirely:
16git revert HEAD

💡 Pro tip

Write commit messages that explain WHY you made the change, not WHAT you changed. Git already shows you what changed. Bad: "updated files." Good: "Fixed navbar not showing on mobile."

The Commands You'll Actually Use

Here's your Git starter pack:

| Command | What it does | When to use it | |---------|-------------|---------------| | git status | See what changed | Before every commit | | git add . | Stage all changes | When you're ready to save | | git commit -m "message" | Save a snapshot | After staging changes | | git log --oneline | See your commit history | When you want to review | | git diff | See exactly what changed | When you want details | | git branch | See/create branches | When starting new features | | git checkout -b name | Create and switch to a new branch | Starting a new feature | | git merge branch-name | Combine branches | When a feature is done | | git push | Upload to GitHub | When you want to share/backup | | git pull | Download latest changes | When working with a team |

Branches: Parallel Universes

Branches are like parallel universes for your code. You can experiment without messing up the main version:

1# You're on the main branch (the 'official' version)
2git branch
3# * main
4
5# Create a new branch for a feature
6git checkout -b add-dark-mode
7
8# Now you're in a parallel universe!
9# Make changes, break things, experiment...
10# The main branch is completely unaffected.
11
12# Happy with your changes? Merge them back:
13git checkout main
14git merge add-dark-mode
15
16# Your dark mode feature is now part of the main code!

⚠️ Heads up

Never work directly on the main branch for big changes. Always create a new branch first. This way, if things go wrong, your main code stays safe. It's the number one habit that separates beginners from people who've been burned before.

GitHub: Git in the Cloud

Git lives on your computer. GitHub is where you put your code online so you can:

  • Back up your code (in case your laptop breaks)
  • Share code with teammates
  • Show off your projects (it's like a portfolio for developers)
1# Connect your local project to GitHub:
2git remote add origin https://github.com/yourname/my-project.git
3
4# Upload your code:
5git push -u origin main
6
7# Download someone else's project:
8git clone https://github.com/someone/cool-project.git

The "Oh No" Commands

Things go wrong. Here's how to fix them:

1# Undo changes to a file (before staging):
2git checkout -- filename.js
3
4# Unstage a file (you added it but changed your mind):
5git reset HEAD filename.js
6
7# Undo the last commit (but keep the changes):
8git reset --soft HEAD~1
9
10# See what a file looked like 3 commits ago:
11git show HEAD~3:filename.js

Quick Recap

  • Git takes snapshots (commits) of your code
  • Three steps: git add (stage) → git commit (save) → git push (upload)
  • Branches let you experiment without breaking the main code
  • GitHub = Git in the cloud (backup + sharing)
  • Write good commit messages (explain why, not what)
  • When in doubt, make a new branch before experimenting

💬 Denise says

Git felt overwhelming to me at first — so many commands! But honestly, you'll use the same 5 commands 95% of the time: status, add, commit, push, and pull. That's your daily workflow. Everything else is for special situations. Start with those five and you're golden. You'll never lose code again, and future you will be SO grateful.

📸

Photo coming soon ✨

🚀

Want to keep going?

Tell me what you want to build next and I'll help you write the code.

Start Building ✨