Git Remote Advanced
In this page:
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
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
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
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
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
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
- दूसरे remote को भी
originनाम देना, जोremote origin already existsसे fail होता है;upstreamजैसा एक अलग नाम इस्तेमाल करें। - एक remote हटाना और hosted repository के delete होने की उम्मीद करना, जबकि
git remote removeसिर्फ आपकी local configuration delete करता है। - बिना 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 हैं।
Chapter Quiz — Complete all 11 topics to unlock
0/11 topics done
Complete these topics first: