← Back to Git Course | Chapter 7: Collaboration | Lesson 3 of 6

Git Fork और Contribute

एक fork किसी friend की recipe book को अपनी shelf पर copy करने जैसा है ताकि आप freely changes try कर सकें, और फिर अपने सबसे अच्छे ideas उन्हें वापस offer कर सकें।
Syntax
bash
git clone https://github.com/your_name/repo.git
git remote add upstream https://github.com/original_owner/repo.git
git fetch upstream

एक Fork क्या है?

एक fork किसी और की repository की, इसकी पूरी history सहित, आपके अपने account के तहत एक पूरी copy है, जिसे आप original पर किसी permission की ज़रूरत के बिना जैसे चाहें modify करने के लिए free हैं। यह किसी ऐसे project में contribute करने के लिए standard entry point है जिसमें आपके पास push access नहीं है।

उदाहरण: What is a Fork?

bash
git clone https://github.com/yourname/repo.git

Upstream Remote Add करना

Default रूप से आपका fork सिर्फ खुद के बारे में जानता है — original repository को upstream नाम का एक remote add करना (git remote add upstream <url>) आपको उस project से नई commits fetch करने का एक तरीका देता है जिसे आपने fork किया, जो आपके fork को सिर्फ exist करने से automatically नहीं मिलता।

उदाहरण: Adding the Upstream Remote

bash
git remote add upstream https://github.com/original/repo.git

अपना Fork Sync करना

क्योंकि आपका fork आपके इसे बनाने के समय का एक snapshot है, original project बिना आपके deliberately sync किए आगे बढ़ता रहता है — upstream से fetch करना और उन changes को अपनी local branch में merge (या rebase) करना आपके fork को बाद में cleanly वापस merge होने के लिए बहुत out of date drift होने से बचाता है।

उदाहरण: Syncing your Fork

bash
git fetch upstream
git checkout main
git merge upstream/main

अपने Fork में Changes Push करना

hosting platform पर आपका fork आमतौर पर origin remote है, इसलिए locally commit करने के बाद आप exactly वैसे ही origin (आपका fork) में push करते हैं जैसे आप अपनी किसी repository के साथ करते — यही आपकी branch को visible बनाता है और एक pull request खोलने के लिए available।

उदाहरण: Pushing Changes to your Fork

bash
git push origin feature-x

एक Fork से Pull Request खोलना

आपकी branch fork में push होने के बाद, hosting platform की website पर एक pull request खोलना destination की तरह original repository और source की तरह आपके fork की branch target करता है — यही actual proposal है जिसे एक maintainer review और merge करता है।

उदाहरण: Opening a Pull Request from a Fork

bash
git push origin feature-x
# then open a pull request from yourname:feature-x to original: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. अपने fork के बजाय original repository clone करना, ताकि आप अपनी branch push न कर सकें।
  2. सीधे अपने fork की main branch पर काम करना, जो upstream के साथ sync करना गंदा बना देता है; एक feature branch इस्तेमाल करें।
  3. upstream remote add करना भूल जाना, ताकि git fetch upstream fail हो और आपका fork पीछे रह जाए।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

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.