๐Ÿ”’ Members-only lesson โ€” thanks for supporting devnotes
← back to course
progress is saved in this browser โ€” no account needed
devnotes / Developer Tools / Lesson 2
lesson 2 of 6 ยท premium

Git Basics: Tracking Changes Without Fear

20 min ยท Developer Tools

The single biggest confidence boost in coding is knowing you can never truly lose your work. Git saves snapshots of your project as you go, so you can always go back โ€” that safety net is worth learning on its own, even before you touch GitHub.

What Git actually is

Git is a version control system โ€” it takes snapshots ("commits") of your project over time, so you have a full history of every change, who made it, and why. It runs entirely on your computer; GitHub (next lesson) is a separate service for storing that history online.

Turning on Git for a project

$ cd my-project $ git init

git init turns the current folder into a Git repository โ€” it starts tracking changes from this point forward. You only run this once per project.

The three-stage mental model

1
Working directoryYour files, as you're actively editing them
2
Staging areaChanges you've marked as "ready to save" with git add
3
Commit historyPermanent snapshots saved with git commit

This two-step "stage, then commit" process feels like extra work at first โ€” its actual purpose is letting you choose exactly which changes go into each snapshot, instead of saving everything blindly.

The core daily workflow

$ git status # shows what's changed since your last commit $ git add index.html # stages one specific file $ git add . # stages every changed file at once $ git commit -m "Add navigation bar" # saves a permanent snapshot with a description
quick tip
Run git status constantly โ€” before and after almost everything. It never changes anything, it just tells you exactly what Git currently sees, which builds the habit of always knowing your project's state.
AD SLOT โ€” 728ร—90 or responsive (mid-lesson)

Writing good commit messages

WeakBetter
fix stuffFix broken image links in footer
updateAdd responsive styles for mobile nav

A good rule: someone reading only your commit messages, six months from now, should understand what changed and roughly why โ€” without opening a single file.

Looking at your history

$ git log # shows every commit, newest first $ git log --oneline # the condensed, much more readable version

Undoing mistakes: the safety net in action

$ git restore file.html # throws away uncommitted changes to one file, back to the last commit $ git restore --staged file.html # un-stages a file without losing your edits
the actual payoff
This is the moment Git earns its reputation: as long as you've committed your work, git restore means a bad experiment or a broken change is never permanent. You can always get back to a known-good state.

Ignoring files on purpose

# .gitignore file, one entry per line: node_modules/ .env .DS_Store

A .gitignore file tells Git which files to never track โ€” things like dependency folders, secret keys, or system files that don't belong in your project history.

Try it yourself

exercise
Create a new folder, run git init inside it, create a file, and run git add then git commit -m "..." with a clear message. Run git log --oneline to see your first commit in history.

Level up: practice the undo

exercise 2
Edit that same file and save it โ€” don't commit yet. Run git status to see it listed as changed. Then run git restore on it and confirm the file goes back to exactly how it was in your last commit.
โœ“ quick check โ€” 3 questions

1. What does git add do?

2. What does git log show?

3. What's the purpose of a .gitignore file?

what's next
Lesson 3 takes this online: GitHub, pushing your commits somewhere safe, and how the entire devnotes site you've been reading is hosted using exactly what you'll learn.
bottom line
Git tracks your project as a series of committed snapshots. git add stages, git commit saves permanently, and git restore is your undo button โ€” as long as you commit regularly, you're protected from losing work.
AD SLOT โ€” 300ร—250 or responsive (in-lesson)
next upLesson 3: GitHub
Continue โ†’