← Back to Git Course | Chapter 4: Remote Repositories | Lesson 5 of 11

GitHub Remote Branch

origin/main जैसी Remote-tracking branches आपके last fetch पर एक remote repository कैसी दिखती थी यह याद रखने का Git का तरीका हैं, जो यह बताना possible बनाता है कि pull या push करने से पहले आपकी local branches कितनी diverge हुई हैं।
Syntax
bash
git fetch remote_name
git branch -r
git log remote_name/branch_name

एक Remote-Tracking Branch क्या है?

origin/main जैसी एक remote-tracking branch एक read-only local bookmark है जो record करती है कि आपके last fetch पर remote पर एक branch कहाँ point करती थी -- यह कोई branch नहीं जिसमें आप directly commit करें, यह बस remote की state reflect करती है ताकि Git इसे आपके local काम के against compare कर सके।

उदाहरण: What is a Remote-Tracking Branch?

bash
git fetch origin
git log origin/main

Remote Branches List करना

git branch -r सिर्फ remote-tracking branches list करता है, जबकि git branch -a local और remote-tracking branches साथ list करता है, जो remote पर exist करने वाली हर branch देखने के लिए उपयोगी है भले ही आपने अभी उनमें से किसी को locally checkout न किया हो।

उदाहरण: Listing Remote Branches

bash
git branch -r
git branch -a

origin/main और Local main Branch

local main branch और remote-tracking origin/main branch अलग references हैं जो एक-दूसरे से drift हो सकती हैं -- git log से उन्हें compare करना locally बनाई गई ऐसी commits दिखाता है जो अभी push नहीं हुईं, या दूसरों की बनाई ऐसी commits जो अभी pull नहीं हुईं।

उदाहरण: origin/main and the Local main Branch

bash
git log main..origin/main
git log origin/main..main

Fetch बनाम Pull

git fetch remote से नई commits download करता है और origin/main जैसी remote-tracking branches update करता है बिना किसी local branch या working directory को बदले, जबकि git pull same fetch करता है और फिर तुरंत उन commits को current branch में merge (या rebase) कर देता है।

उदाहरण: Fetch vs Pull

bash
git fetch origin
git pull origin main

एक Remote Branch को Locally Checkout करना

सिर्फ remote पर exist करने वाली एक branch checkout करना, git checkout -b <name> origin/<name> या git switch -c <name> origin/<name> इस्तेमाल करके, एक नई local branch बनाता है जो remote branch track करना शुरू कर देती है, इसलिए future plain git pull और git push commands को exactly पता होता है कि कहाँ sync करना है।

उदाहरण: Checking Out a Remote Branch Locally

bash
git checkout -b feature-x origin/feature-x
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. origin/main को एक editable branch मानकर इसमें commit करना, जबकि यह एक read-only bookmark है जिसमें आप directly commit नहीं कर सकते।
  2. बिना git fetch चलाए origin/main के up to date होने की उम्मीद करना, ताकि यह पुरानी information दिखाए।
  3. local main को origin/main से confuse करना, जहाँ merge या pull करने तक दोनों अलग हो सकते हैं।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.