Version Control with Git
Why every real project tracks history, and how commits, branches, merges, and pull requests turn Git into a daily frontend workflow.
Version Control with Git
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Git stores a full history of snapshots, so you can always get back to any working version of the project instead of overwriting it.
- A commit is a deliberate checkpoint with a message, not an autosave — grouping related changes into one commit is what makes history useful later.
- Branches let you develop a feature in isolation and merge it back only once it works, instead of breaking the shared codebase while you experiment.
- Merge conflicts happen when two branches changed the same lines; Git stops and asks a human to decide, it doesn't guess.
- A pull request is a conversation about a branch before it merges — the actual review and discussion layer that GitHub adds on top of plain Git.
The problem before Git existed
Picture working on a project alone, in a folder, with no version control. You’re mid-way through restructuring a component when you realize the old approach actually worked better for one edge case. Now what? Maybe there’s a folder called project-backup, or project-final, or project-final-v2-ACTUAL. Multiply that chaos by a team of five people editing the same files, and you get overwritten work, “wait, who deleted that function,” and Slack messages that say “don’t touch app.js right now, I’m in the middle of something.”
Git exists to solve exactly this. It’s a system that records the state of your entire project at chosen points in time, lets you jump back to any of those points, and lets multiple people work on different pieces of the same codebase without stepping on each other. It doesn’t store a stack of whole-folder copies — it’s smarter than that, tracking just the changes — but the mental model of “a history of snapshots you can return to” is the right one to start with.
Commits: deliberate checkpoints, not autosave
A commit is a snapshot of your project at a specific moment, with a message describing what changed and why. The key word is deliberate. Git doesn’t commit automatically every time you save a file — you decide when a set of changes is coherent enough to become a checkpoint, and you write a message that your future self (or a teammate) will actually understand six months later.
This is why the staging area matters. Before you commit, you git add the specific files or changes you want included. This two-step dance — stage, then commit — exists so you can split a messy afternoon of work into several focused commits: one for the bug fix, one for the new feature, rather than one giant commit titled “stuff.” Good commit history is a gift to your future self: git log becomes a readable story of how the project evolved, not a wall of noise.
Branches: working in isolation
The real power shows up once you need to try something without disturbing what already works. A branch is a separate line of development that starts as a copy of your current code and diverges from there. You might create a feature/dark-mode branch, make a dozen commits on it while main stays untouched and deployable, and only bring your changes back over once dark mode actually works.
This matters more than it sounds. Without branches, every half-finished experiment lives directly on the code everyone else depends on. With branches, the default state of main stays stable, and risky or in-progress work is quarantined until it’s ready. Merging is the act of folding a branch’s history back into another branch — usually main — combining both sets of changes into one.
When merges go wrong
Most merges are automatic: Git looks at what changed on each branch and combines them without trouble, because the changes touched different lines. A merge conflict happens when both branches edited the same lines of the same file in incompatible ways. Git can’t guess which version you want, so it stops, marks the conflicting sections directly in the file with <<<<<<< and >>>>>>> markers, and leaves it to you to pick a resolution, edit the file into its final correct form, and commit the result.
Conflicts feel scary the first time, but they’re not a sign something broke — they’re Git correctly refusing to silently lose someone’s work. The fix is always the same shape: open the file, decide what the final version should look like, remove the markers, stage, and commit.
GitHub, pull requests, and the daily loop
Git itself is a local tool — it works on your machine with no network required. GitHub (and similar services like GitLab) adds a hosted copy of the repository that a team shares, plus a layer of collaboration tools on top. The most important of these is the pull request (PR): a request to merge one branch into another, bundled with a diff view, a place for comments, and often automated checks like tests or a linter that have to pass first.
A typical frontend workflow looks like this: pull the latest main to stay current, create a branch for your task, commit as you go with clear messages, push the branch to GitHub, open a pull request, address review comments, and merge once it’s approved and checks are green. That loop — branch, commit, push, review, merge — is the daily rhythm of working on almost any real codebase, and everything else in Git (rebasing, cherry-picking, stashing) is a refinement on top of that same core idea: a history you control, in isolated lines of work, merged back deliberately.
Check yourself
What's the difference between staging a change and committing it?
Staging (git add) marks which changes should go into the next commit; committing (git commit) actually records that snapshot in history. Staging exists so you can build one clean commit out of a messy set of edits.
Why does Git refuse to merge two branches automatically sometimes?
Because both branches changed the same lines of the same file in different ways, and Git has no way to know which version — or what combination — you actually want, so it marks the file as conflicted and waits for you to resolve it by hand.
Why use a pull request instead of just merging a branch directly?
A pull request gives teammates a diff to review, a place to leave comments, and a point where automated checks (tests, linting) can run before the code lands on the main branch, instead of code going straight in unexamined.
What problem does a .gitignore file solve?
It tells Git which files to never track — things like node_modules, build output, or .env secrets — so they don't get committed, bloat the repository, or leak credentials.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.