What is Source Control?
Think of it as a time machine for your code. It tracks every modification to your project in a database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake.
timelapse Try the Time Machine
Drag the slider to see how source control allows you to visit previous versions of a file.
Commit: d1e514g
Added timestamp support
2
3
4
5
6
7
8
// app.js
function greet(name) {
const time = new Date().getHours();
console.log(`[${time}:00] Hello ${name}`);
}
greet('Dave');
How git rebase Works
Rebasing is the process of moving or combining a sequence of commits to a new base commit. It's like taking your work, detaching it from where you started, and re-playing it on top of the latest version of the main project.
tune Controls
You are on the feature branch. The main branch has moved ahead. Let's rebase your work onto the latest main.
Current Status
terminal Step Log
Feature branch diverged from Main at commit C2.
Rebase vs. Merge: Which to use?
Both commands integrate changes from one branch into another, but they do it in very different ways.
Git Merge
Creates a new "merge commit" that ties two histories together. Preserves the exact history of when and how code branched.
- check Non-destructive (safe).
- check Preserves complete history.
- close Can clutter history with "merge bubbles".
Git Rebase
Moves the entire feature branch to begin on the tip of the main branch. Effectively rewriting history.
- check Linear, clean history.
- check Easier to use `git bisect` (debugging).
- close Dangerous on public/shared branches.
| Scenario | Recommendation | Why? |
|---|---|---|
| Updating a local private feature branch | git rebase | Keeps your work clean and linear before sharing. |
| Merging a completed feature into Main | git merge --squash | Combines all work into one neat commit on Main. |
| Public branch that others are working on | git merge | NEVER rebase public branches! It rewrites history and breaks others' work. |