Ravindra BagaleCourses & study guides Track your progress

Guides

शुरुआती के लिए Git Branching और Pull Requests

Read this guide in: English · मराठी · हिंदी

Why branches और pull requests चाहिए? क्योंकि जब developers सब main पर लिखते हैं और operations (server side) को अधूरा काम मिलता है तब असली problem आता है। दो लोग अलग features एक ही live line पर push करते हैं; users को break महसूस होता है; review नहीं होता। Branch मतलब एक काम के लिए side line। Pull request (PR) मतलब merge से पहले review table — ताकि server-side person सिर्फ़ team‑सहमत काम देखे।

दोस्तों, पहले “दोनों ने main edit किया” crash देखो। फिर PR साफ़ लगेगा।

संक्षिप्त उत्तर

  1. Developers — हर एक को बदलाव खत्म करने की जगह चाहिए।
  2. Operations — server-side employee जो stable main से deploy करे, WIP नहीं।
  3. Problem — दोनों main पर push; मिली‑जुली history; review नहीं।
  4. Branch + PR — side line → review → तैयार होने पर merge।
  5. Pocket loop: update main → branch → commit → push → open PR → merge।

Language: English · मराठी · हिंदी

Branching और PRs क्यों?

  1. Developers features खत्म करते समय operations आज जो deploy करेगा उसे न तोड़ें।
  2. Operations को main releasable चाहिए।
  3. Review server देखने से पहले गलतियाँ पकड़ता है।

Git basics और अपना GitHub repo चाहिए।

Problem? Suppose we are…

Suppose we are building Instagram (like updates)

एक developer main पर profile badge; दूसरा उसी main पर feed ranking। दोनों push। Operations पूछता है: production पर कौन‑सा commit?

Suppose we are working at Netflix and we are giving updates

दो Netflix-style home-row fixes अधूरे main पर। लाखों viewers को बुरा merge महसूस हो सकता है। Merge से पहले review optional नहीं।

Suppose you are working in Infosys on a client project

Client operations सिर्फ़ reviewed बदलाव स्वीकारता है। PR = क्या बदला, किसने approve किया, क्या test हुआ — उनके server से पहले।

Git: working tree, staging, commit history Edit files in the working tree, git add to stage, git commit to save a snapshot. Commits form history on the branch. Working tree edit files README.md add Staging git add index commit Repository (.git) git commit · snapshots c1 c2 c3 main → History answers: which build is live? (no mystery zip) status → add → commit Then git push shares the same history with the team / operations

Git path: edit in the working tree, git add to stage, git commit to save a snapshot on the branch history.

Branch + PR उसी लड़ाई का जवाब कैसे देता है

git checkout main
git pull
git checkout -b feature/profile-badge
git add -A
git commit -m "Add profile badge field"
git push -u origin feature/profile-badge

GitHub पर: Compare & pull request → base main → describe → CI (GitHub Actions) → merge → branch delete → git checkout main && git pull && git branch -d feature/profile-badge।

Ravindra Bagale's Tip

विशाल “सब refactor” PRs review थका देते हैं — Infosys client ops पर बीस अधूरे features डालने जैसा। एक branch पर एक उद्देश्य। याद रखो।

Common errors

Pain कारण Fix
PR conflicts Main आगे बढ़ गया Main से update, fix, push
गलती से main पर push गलत branch Main protect करें; branches इस्तेमाल करें
branch is behind Main pull भूले नई branch से पहले main update
Empty PR Branch पर commits नहीं Feature branch पर commit, push
Branch delete नहीं होता अभी checked out पहले git checkout main

Samajla ka? Why branch/PR = अधूरा काम server-side तक न जाए; Instagram / Netflix / Infosys “suppose”; side line → review → merge। आज रात एक छोटी PR।

Frequently asked questions

What is a branch?

A branch is a movable line of commits so you can work without breaking main.

What is a pull request?

A PR asks to merge your branch into another branch after review.

Why not commit only on main?

Teams use branches so unfinished work stays isolated and reviews stay clear.

What is a merge conflict?

Two branches changed the same lines. Git asks you to pick the final text, then commit the fix.

Should I force-push?

Avoid force-push on shared branches. Prefer normal push after rebase only when your team agrees.

How long should a branch live?

Prefer short branches and small PRs — easier to review and safer to merge.