New to Git — step 2

Never lose a change again.

You've got the terminal down. Next is Git — the tool that remembers every version of your project so you can always see what changed, undo it, or go back. This is what makes it safe to let an AI agent touch real files.

← Start with step 1: the terminal

00

What even is Git?

Two words that get used interchangeably but mean different things.

Git

Is a program on your computer. Every time you tell it to, it saves a snapshot of your project — what changed, who changed it, and when. Think of it as a save-history for your whole folder, not just one file: your own version control, and your own Google Drive for code, running locally.

GitHub / GitLab

Is the cloud service you send that history to — so it's backed up somewhere that isn't just your laptop, and so other people (or other machines) can see it too. Git is the tool; GitHub and GitLab are places to put what it made. (This project itself lives on GitLab.)

01

The three states

Every change you make passes through three stages, in order. This is the one idea worth really understanding — everything else builds on it.

1
Unstaged

You edited a file. Git noticed. Nothing is saved yet — it's just sitting there, changed.

git add
2
Staged

You've told Git "this change is going in the next save." Nothing's permanent yet — you can still change your mind.

git commit
3
Committed

Permanently in the history now, with your name and a timestamp attached. This is a real save point you can always come back to.

terminal
you@laptop gravity % git status
On branch main
Changes not staged for commit:
  modified:   notes.txt

you@laptop gravity % git add notes.txt
you@laptop gravity % git status
On branch main
Changes to be committed:
  modified:   notes.txt

Same file, same change — git status just told you which of the three states it's in. Run it often. It never lies.

02

Try it: your first commit

Same flow, two ways to do it — the terminal, and a GUI. Pick whichever clicks for you; they end up in the exact same place.

terminal
you@laptop gravity % echo "hello" > notes.txt
you@laptop gravity % git add notes.txt
you@laptop gravity % git commit -m "add notes"
[main 4f2a1c9] add notes
 1 file changed, 1 insertion(+)
you@laptop gravity % git log
commit 4f2a1c9
Author: you
Date:   just now
    add notes

-m "add notes" is the commit message — a short note to future-you about what changed and why. git log shows the history — that commit is now permanent.

git gui — gravity
Unstaged Changes
notes.txt
↓ click to stage ↓
Staged Changes
notes.txt

Click a file to stage it (same as git add), type a message, click Commit (same as git commit). No typing the file name exactly right, no memorizing flags — if that's more comfortable while you're learning, use it. Nothing wrong with that.

03

See your history — gitk & git gui

There are dozens of Git apps out there. These two are the simplest, and they already came with Git — or one command away.

terminal
brew install git-gui

One formula, installs both gitk and git gui. No Homebrew yet? See the terminal page's install section.

gitk — your history, as a picture

gitk — gravity
add notes
you · just now
Set up the homepage hero
you · 2 days ago
Initial commit
you · 2 days ago

Every dot is a commit — the same list git log printed as text a moment ago, newest at the top. This is the whole point of learning Git: nothing here is a mystery, it's just every save you ever made, in order.

04

Branches are pointers, not copies

The single most common misunderstanding about Git — worth getting right early.

A branch is not a second copy of your whole project. It's just a little sticky note — a name, like main — stuck onto one specific commit. When you make a new commit, Git just moves that sticky note forward to point at it.

That's what makes branches fast and cheap: creating one doesn't copy any files, it just adds another sticky note somewhere in the same history you already have.

main

Three commits, one pointer — main just labels the newest one.

05

Going back in time, carefully

If a branch is a pointer, moving it backward means going back to an older save — and that's exactly what git reset --hard does.

git reset --hard can throw work away — with no undo

It moves the branch pointer to wherever you tell it, and makes your files match that older commit exactly — including deleting any uncommitted changes sitting in the unstaged or staged states from earlier in this page. If it wasn't committed yet, it doesn't survive.

The habit that keeps you safe: run git status first, every time. If it says anything is unstaged or staged, deal with that (commit it, or be sure you don't need it) before you reset anything.

06

Local vs. the cloud

Your laptop's idea of "what's on GitHub" is a snapshot from the last time you checked — not a live view. It goes stale quietly.

git fetch — recommended

Goes and checks what's actually on GitHub or GitLab, downloads anything new — but doesn't touch your files. You look at what changed first, then decide what to do about it. Look before you leap.

git pull — use with caution

Does a fetch, then immediately merges whatever it found into your work, with no pause to look first. Sometimes that's fine; sometimes it's a surprise merge you weren't ready for. This project's own recommendation: reach for git fetch on purpose, every time, and skip git pull.

And the other direction — once you've committed something and you're ready to back it up and share it, git push sends your commits up to GitHub/GitLab. That's the whole loop: fetch to look, commit to save locally, push to share.

This is what makes AI safe to hand the keys to.

When an AI coding agent edits real files, Git is what lets you see exactly what it touched (git status, git diff), decide whether to keep it, and know you're never more than one commit away from where you started. That's the whole safety net — and you just learned how it works.