π§ Scenario: Building a Node.js API Project with a Team¶
You and 2 developers are building:
Weβll go from:
β Creating repo β Branching β Conflict β Rebase vs Merge β Undo mistakes β PR flow β Production tagging β Disaster recovery
1οΈβ£ What Git Actually Does (Example)¶
Imagine:
Day 1 β You write login feature Day 2 β Teammate writes payment feature Day 3 β You both change same file
Git keeps snapshots of every version.
Git was created by Linus Torvalds and powers platforms like GitHub.
2οΈβ£ Starting a Real Project¶
Step 1 β Create folder¶
Now Git creates .git folder.
3οΈβ£ First Commit (Real Example)¶
Create app.js
Check status:
It shows:
Add & commit:
π What happened internally?
Git created:
- Blob (file content)
- Tree (folder structure)
- Commit (snapshot)
4οΈβ£ Connect to GitHub (Real Example)¶
You create repo in GitHub UI.
Then:
git remote add origin https://github.com/yuva/payment-api.git
git branch -M main
git push -u origin main
Now code is online.
5οΈβ£ Real Team Workflow (Feature Branch)¶
You are adding Login API¶
Edit app.js
Commit:
Now you create a Pull Request in GitHub.
6οΈβ£ Meanwhile Teammate Changes Same File π¬¶
Your teammate creates:
They edit app.js:
console.log("Payment API started");
function processPayment() {
console.log("Payment processed");
}
processPayment();
They merge into main.
7οΈβ£ Now You Try To Merge π± (Conflict Example)¶
You:
Git says:
File becomes:
console.log("Payment API started");
<<<<<<< HEAD
function processPayment() {
console.log("Payment processed");
}
=======
function login() {
console.log("User logged in");
}
>>>>>>> feature/login
8οΈβ£ How You Fix Conflict (Real Fix)¶
You edit file manually:
console.log("Payment API started");
function login() {
console.log("User logged in");
}
function processPayment() {
console.log("Payment processed");
}
login();
processPayment();
Then:
β Conflict resolved.
9οΈβ£ Merge vs Rebase (With Example)¶
Merge¶
Creates extra commit:
History looks like:
Rebase (Cleaner)¶
Instead:
Now history becomes linear:
β Cleaner history β Donβt rebase shared branches
π Undo Mistakes (Real Situations)¶
β Situation 1: Wrong Commit Message¶
β Situation 2: Accidentally Committed .env¶
β Situation 3: Delete Last Commit But Keep Code¶
β Situation 4: Completely Delete Last Commit¶
1οΈβ£1οΈβ£ Recover Deleted Branch (Disaster Recovery)¶
You deleted branch accidentally:
Recover:
Git never truly forgets immediately.
1οΈβ£2οΈβ£ Stash Example (Real Scenario)¶
You are coding but boss says switch branch urgently.
Later:
Your work returns.
1οΈβ£3οΈβ£ Production Release Example¶
After testing:
Now CI/CD pipeline triggers Docker build.
Example:
1οΈβ£4οΈβ£ Real DevOps Flow (Enterprise Level)¶
Typical company flow:
- Developer β feature branch
- PR β code review
- CI runs tests
- Merge to main
- Tag release
- Docker build
- Deploy via Terraform
- Monitor
1οΈβ£5οΈβ£ Advanced Real Scenario: Squash Commits¶
You made 5 small commits:
Before PR:
Change to:
Now only 1 clean commit.
1οΈβ£6οΈβ£ Real Multi-Developer Collaboration Flow¶
Team uses:
GitHub Flow (Most Modern Teams)¶
- main (production)
- feature branches
- PR review
- CI pipeline
Used widely in GitHub based teams.
1οΈβ£7οΈβ£ Git Internal Storage (Advanced Understanding)¶
Inside:
Youβll find:
- objects/
- refs/
- HEAD
Git stores everything as hashed objects (SHA).
1οΈβ£8οΈβ£ Real Interview Level Questions¶
Q: Difference between revert and reset?¶
resetβ rewrites historyrevertβ creates new undo commit
Q: Detached HEAD?¶
When you checkout specific commit:
You are not on branch.
π― Complete Real Project Flow Summary¶
git clone
git checkout -b feature/api
# code
git add .
git commit -m "Add API"
git push origin feature/api
# create PR
# merge
git checkout main
git pull
git tag v1.1
git push origin v1.1