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

Git pull Command

git pull mailbox check करने और तुरंत सारी नई letters अपने folder में डालने जैसा है। यह नया काम लाता है और उसे एक step में आपके साथ blend करता है।
Syntax
bash
git pull remote_name branch_name
git pull --rebase remote_name branch_name

Git Pull क्या है?

git pull sequence में दो operations का shorthand है: यह एक remote से नई commits fetch करता है, फिर उन्हें तुरंत आपकी इस समय checked-out branch में merge करता है, same step में आपकी working files update करते हुए।

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

bash
git pull origin main

Git Pull कैसे काम करता है

Under the hood, git pull पहले आपकी remote-tracking branch (जैसे origin/main) को server से match करने के लिए update करता है, फिर उस updated reference और आपकी local branch के बीच एक normal merge चलाता है।

उदाहरण: How Git Pull Works

bash
git fetch origin
git merge origin/main

Rebase के साथ Pull करना

Default रूप से वह merge step एक merge commit बनाता है अगर histories diverge हुई हों; git pull --rebase इसके बजाय merge को rebase से replace करता है, आपके project की history को हर sync पर branch होने के बजाय linear रखते हुए।

उदाहरण: Pulling with Rebase

bash
git pull --rebase origin main

Remote से एक Specific Branch Pull करना

git pull origin <branch> आपको किसी भी branch सीधे आपके local database में pull करने देता है, सिर्फ जो branch आपने इस समय checkout की है वह नहीं -- पहले switch किए बिना teammate की branch लाने के लिए उपयोगी। git pull origin <branch> चलाना जब उस नाम की कोई local branch अभी exist न करे तब भी पहले इसे track करने वाली एक local branch checkout करना ज़रूरी है -- git checkout --track origin/<branch> (या git switch -c <branch> origin/<branch>) वह local branch बनाता है, और बाद में एक plain git pull इसे remote branch की latest commits के साथ updated रखता है।

उदाहरण: Pulling a Specific Branch from Remote

bash
git pull origin feature-x

Pull Conflicts Handle करना

अगर आपके local uncommitted changes incoming remote changes से conflict करें, git pull कुछ भी चुपचाप overwrite करने के बजाय एक error के साथ pause हो जाता है -- pull आगे बढ़ने से पहले आपको अपने local changes commit, stash, या discard करने होंगे।

उदाहरण: Handling Pull Conflicts

bash
git pull origin main
# error: local changes would be overwritten
git stash
git pull origin main
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. same files छूने वाले uncommitted changes के साथ git pull चलाना, एक error या conflict का कारण बनते हुए।
  2. यह जाने बिना pull करना कि यह merge करता है, ताकि एक unexpected merge commit दिखे; git pull --rebase इससे बचाता है।
  3. गलत branch पर git pull चलाना, गलती से remote changes को एक feature branch में merge करते हुए।

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.