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

Git Remote Advanced

एक project में एक से ज़्यादा remote हो सकते हैं, आपकी अपनी copy और original author की copy दोनों के addresses रखने जैसा। इस तरह आप एक को काम भेज सकते हैं और दूसरे से updates receive कर सकते हैं।
Syntax
bash
git remote add remote_name repository_url
git remote rename old_name new_name
git remote remove remote_name
git fetch remote_name

कई Remotes के साथ काम करना

एक repository एक remote तक limited नहीं है — एक fork से काम करते समय एक common pattern है origin को आपके अपने fork की ओर pointing रखना साथ ही upstream नाम का एक दूसरा remote add करना जो original repository की ओर point करता है जिसे आपने fork किया। यह आपको अभी भी upstream से latest changes pull करते हुए अपना काम origin में push करने देता है।

उदाहरण: Working with Multiple Remotes

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

एक Remote Rename करना

Remote names बस local aliases हैं जिन्हें आप remote repository को affect किए बिना कभी भी rename कर सकते हैं। git remote rename Git के इसे track करने वाली हर जगह alias update करता है, remote-tracking branches सहित, इसलिए origin/main automatically newname/main बन जाता है।

उदाहरण: Renaming a Remote

bash
git remote rename origin old-origin

एक Remote Remove करना

git remote remove एक remote की configuration पूरी तरह delete कर देता है, इसकी origin/feature-x जैसी सारी remote-tracking branches सहित, लेकिन इसका actual remote repository या आपकी अपनी local branches पर कोई effect नहीं होता। यह एक stale connection साफ करने के लिए उपयोगी है, जैसे एक project migration के बाद अब न चाहिए वाला एक पुराना upstream।

उदाहरण: Removing a Remote

bash
git remote remove upstream

Stale Remote-Tracking Branches Pruning करना

जब remote पर एक branch delete हो जाती है, आपकी local copy अभी भी उसके last known commit की ओर point करने वाली एक remote-tracking branch रखती है जब तक आप explicitly इसे साफ न करें। git fetch --prune (या shorter git fetch -p) remote-tracking branches हटाता है उन सबके लिए जो remote पर अब exist नहीं करतीं, git branch -r को accurate रखते हुए।

उदाहरण: Pruning Stale Remote-Tracking Branches

bash
git fetch --prune

एक Fork को Upstream के साथ Sync करना

एक fork को current रखने का मतलब है upstream से fetch करना, upstream की main branch को अपनी local main में merge (या rebase) करना, और फिर result को अपने खुद के origin में push करना ताकि GitHub पर आपका fork भी latest history reflect करे। final push skip करना आपके fork की main branch को पीछे छोड़ देता है भले ही आपकी local copy up to date हो।

उदाहरण: Syncing a Fork with Upstream

bash
git fetch upstream
git checkout main
git merge upstream/main
git push 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. दूसरे remote को भी origin नाम देना, जो remote origin already exists से fail होता है; upstream जैसा एक अलग नाम इस्तेमाल करें।
  2. एक remote हटाना और hosted repository के delete होने की उम्मीद करना, जबकि git remote remove सिर्फ आपकी local configuration delete करता है।
  3. बिना permission के upstream पर push करना, जबकि आप आमतौर पर सिर्फ इससे fetch करते हैं और origin में push करते हैं।
चैप्टर सारांश
  • Remote repositories आपके project की hosted copies हैं, जिन्हें git remote से manage किया जाता है।
  • git fetch, git pull, और git push एक remote के साथ changes exchange करते हैं।
  • GitHub, Bitbucket, और GitLab common hosting services हैं।

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.