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

Git fetch Command

git fetch mailbox check करने और नई letters लाने जैसा है बिना उन्हें खोले या अपना desk बदले। आप देखते हैं क्या नया है लेकिन आपका अभी कुछ नहीं बदलता।
Syntax
bash
git fetch remote_name
git fetch remote_name branch_name

Git Fetch क्या है?

git fetch एक remote repository से नई commits, branches, और tags आपके local database में download करता है -- लेकिन critically, यह कभी आपकी working files या current branch नहीं छूता, इसे यह check करने का एक completely safe तरीका बनाते हुए कि क्या बदला।

उदाहरण: What is Git Fetch?

bash
git fetch origin

Fetch बनाम Pull

git pull से key difference यह है कि fetch download करने के बाद रुक जाता है: यह आपकी remote-tracking branches (जैसे origin/main) update करता है लेकिन आपकी actual local branches untouched छोड़ता है, आपको कुछ भी merge करने से पहले git diff या git log से incoming changes review करने देते हुए।

उदाहरण: Fetch vs Pull

bash
git fetch origin
git log origin/main

Specific Branches Fetch करना

git fetch origin <branch> remote की हर branch के बजाय सिर्फ एक specific branch target करता है, जो बड़ी repositories पर time और bandwidth बचाता है जहाँ आपको सिर्फ काम की एक line के updates की परवाह हो।

उदाहरण: Fetching Specific Branches

bash
git fetch origin feature-x

Obsolete Branches Pruning करना

जब teammates remote पर branches delete करते हैं, उन्हें आपकी local remote-tracking references stale हो सकती हैं; git fetch --prune उन्हें automatically साफ करता है, उन branches को local references delete करते हुए जो अब remote पर exist नहीं करतीं।

उदाहरण: Pruning Obsolete Branches

bash
git fetch --prune

Dry Run Fetching

git fetch --dry-run exactly दिखाता है कि एक real fetch actually download किए बिना क्या download करेगा -- actual transfer commit करने से पहले आपका connection test करने या incoming changes preview करने का एक lightweight तरीका।

उदाहरण: Dry Run Fetching

bash
git fetch --dry-run
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. यह उम्मीद करना कि git fetch आपकी files बदल देगा, जबकि यह सिर्फ remote-tracking branches update करता है और आपकी working directory unchanged छोड़ता है।
  2. git fetch चलाना और यह सोचना कि आप up to date हैं, जबकि commits लाने के लिए आपको अभी भी git merge origin/main चाहिए।
  3. एक ऐसा branch name fetch करना जो remote पर exist नहीं करता, जैसे git fetch origin featur, जो एक couldn't find remote ref error देता है।

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.