Lesson 5 — Beginner

Git & Collaboration

Git sirf backup nahi — wo tumhara project ka time machine aur team ka coordination tool hai. Is lesson mein repos, commits, staging aur diffs se shuru karke branches, remotes, PR workflow, commit messages, merge conflicts, .gitignore aur README tak jayenge — end mein doosra developer tumhara repo padh kar chala le, yahi target hai.

⏱ 20 min• Beginner• Data & Persistence Basics

Git kya hai — snapshot ka khel

WHAT

Git har commit mein project ka full snapshot leta hai aur usko history mein store karta hai. Tum past mein kisi bhi point pe ja sakte ho, diff dekh sakte ho, aur branches se parallel versions chala sakte ho.

WHEN

Har code change — chhota ho ya bada. Ek baar aadat ban gayi toh aap kabhi "final_v2_final.py" jaise files nahi banaoge. Git hi versioning ka standard hai.

WHERE

GitHub/GitLab/Bitbucket pe remotes (team ke liye), laptop pe local repo, CI/CD platforms isi se code lete hain. Is course mein bhi har project git repo ke saath aayega.

Chaar jagah yaad rakho: working directory (jahan edit karte ho), staging area (jis change ko next commit mein daalna hai), commit (snapshot + message), aur remote (GitHub jaisa copy jahan push/pull karte ho). Git ka poora khel in chaar ke flow mein hai.

Yaad rakho: Git local hai — commit karne ke liye internet nahi chahiye, sirf push/pull ke liye. Aur commit chhota hona chahiye: ek commit = ek idea.

Staging, commits aur history

git status                  # kya badla, kya staged hai
git diff                    # staged se pehle ka difference — padho
git add app/routes/orders.py
git diff --staged           # jo abhi commit hone ja raha hai — yahi review hota hai
git commit -m "orders: reject past start time with 422"

git log --oneline -5        # history chhoti rakho
git show --stat HEAD        # last commit mein kya badla
Rule: Ek commit = ek idea. Format change aur bug fix ek saath mat karo — baad mein sirf ek ko revert karna ho toh mushkil ho jaata hai.

Branches, remotes aur PR workflow

git switch -c feature/booking-clash     # nayi branch
# ... kaam karo, add, commit ...
git push -u origin feature/booking-clash

# Remote (GitHub) pe PR kholo -> review -> CI green -> merge
# Merge ke baad:
git switch main
git pull                                # main ka latest lo
git branch -d feature/booking-clash      # kaam khatam, branch delete
Rule of thumb: Solo project mein bhi branch pe kaam karo — aadat ban jaayegi, main pe galat commit ka dar nahi rahega, aur PR ka diff review practice ho jaayega.

Merge conflicts — darr nahi, normal cheez

<<<<<<< HEAD
    if starts_at < datetime.now():
        raise HTTPException(status_code=422, detail="Past time")
=======
    if starts_at <= datetime.now(timezone.utc):
        raise ValueError("start must be in the future")
>>>>>>> feature/booking-clash

# 3 steps: dono versions padho -> sahi wala rakho (ya dono ka behtar merge) -> markers hatao
git add bookings.py
git commit                                  # merge complete
Escape hatch: Galat direction mein ja raha ho toh git merge --abort se merge cancel kar sakte ho aur fresh start le sakte ho. Lekin ek baar resolve karke dekho — asli mein 5 minute ka kaam hai.

.gitignore, README aur code review

# .gitignore — env, secrets, generated sab bahar
.env
.env.*
!.env.example

__pycache__/
*.pyc
.venv/
.pytest_cache/
.mypy_cache/

.idea/
.vscode/
.DS_Store
# README.md skeleton — 5 headings kaafi hain

# Bookings API

Chhoti room-booking REST service — FastAPI + PostgreSQL.

## Install & run
uv sync
cp .env.example .env      # apne values daalo
uv run uvicorn app.main:app --reload

## Test
uv run pytest -q

## API
GET    /health     200
POST   /rooms      201 | 422
POST   /bookings   201 | 409, 422

## Config
.env.example dekho — DATABASE_URL zaroori hai.
Handover test: Apna repo doosre laptop pe clone karke README follow karke chalao. Ruk gaye jagah = documentation gap. Yahi test team ke liye bhi lagta hai.

Exercise

Question: Change ko commit se pehle staging area mein daalne wala command? (git ke saath)

Question: Merge conflict file mein upar wale version ko mark karne wale characters kya hain? (poora likho)

Question: Secrets aur env files ko repo mein jaane se rokne wala file ka naam?

Question: Remote se changes apne local repo mein laane wala command? (git ke saath)

Common mistakes

Desi example: Mess ka register — git ka desi analogy

Mess ke register mein har hafte ka page (commit) alag hota hai — pichhla page koi mita nahi sakta, galat likha toh naya correction page. Har naya kaam naye page (branch) par, aur master register mein sirf checked pages aate hain:

bash
git switch -c page-4-booking      # naya page khola
git add . && git commit -m "page-4: 3 bookings added"   # entry likhi
git push origin page-4-booking    # register office bheja
git switch main && git pull       # master ka latest liya
Interview angle — yahan se sawaal aate hain
  • Q: Staging area kyun hota hai — seedha commit kyun nahi? — partial staging, aur commit se pehle ek baar review ka mauka.
  • Q: PR merge se pehle kya check hona chahiye? — diff review, CI green, conflict-free, chhota scoped change.
  • Q: Merge conflict kaise resolve karte hain? — markers padho, sahi version rakho, add + commit.
  • Q: .env aur .venv repo mein kyun nahi jaane chahiye? — secrets leak aur repo bloat; .env.example hi commit karo.
  • Q: Achha commit message kaisa hota hai? — scope + change + why, jaise "auth: expire tokens after 1h to cut replay window".
Lesson complete?

Git ka workflow baith gaya. Agla lesson — AI-Assisted Software Development — mein isi workflow ke saath coding agent ko collaborator banayenge.

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course