Git Submodules
In this page:
git submodule add repository_url path
git clone --recurse-submodules repository_url
git submodule update --init --recursive
एक Submodule Add करना
एक submodule किसी दूसरी Git repository को आपके project की एक subdirectory की तरह embed करता है, एक branch track करने के बजाय एक specific commit पर pinned। यह किसी separate shared library की exact history पर बिना उसकी commits को अपनी repository में merge किए depend करने का standard तरीका है।
उदाहरण: Adding a Submodule
git submodule add https://github.com/user/library.git libs/library
Submodules वाली Repositories Clone करना
जब आप submodules वाला एक project git clone करते हैं, Git submodule directories बनाता है लेकिन उन्हें खाली छोड़ता है — parent repo सिर्फ एक pointer store करता है कि हर submodule किस commit पर होना चाहिए। उन्हें actually populate करने के लिए आपको git submodule init और git submodule update चलाना ज़रूरी है (या --recurse-submodules से clone करना)।
उदाहरण: Cloning Repositories with Submodules
git clone --recurse-submodules https://github.com/user/repo.git
git submodule update --init --recursive
Submodule Code Update करना
git submodule update --remote हर submodule के अपने remote से latest commits fetch करता है और आपके local checkout को match करने के लिए आगे move करता है, लेकिन यह automatically parent repository के pinned pointer को update नहीं करता — आपको अभी भी खुद वह pointer change git add और commit करनी होगी।
उदाहरण: Updating Submodule Code
git submodule update --remote
git add libs/library
git commit -m "Update submodule"
Submodule Commands चलाना
git submodule foreach '<command>' हर registered submodule directory के अंदर sequence में एक arbitrary shell command चलाता है, आपको manually हर एक में cd करने से बचाते हुए — सबमें एक साथ git status चलाने जैसी चीज़ के लिए उपयोगी।
उदाहरण: Running Submodule Commands
git submodule foreach 'git status'
एक Submodule Delete करना
एक submodule को cleanly हटाने के लिए सिर्फ इसका folder delete करने से ज़्यादा चाहिए: आपको इसकी entry .gitmodules और .git/config से हटानी होगी, फिर इसे untrack करने के लिए git rm --cached <path> चलाना होगा, और आख़िर में leftover .git/modules/<path> cache directory delete करनी होगी — इनमें से कोई भी step skip करना stale references पीछे छोड़ देता है।
उदाहरण: Deleting a Submodule
git rm --cached libs/library
rm -rf .git/modules/libs/library
- Submodules वाली एक repository clone करना और खाली folders मिलना, जबकि आपको
git submodule update --init --recursiveया--recurse-submodulesचाहिए। - एक submodule के अंदर changes commit करना और parent project में updated pointer commit करना भूल जाना।
- एक detached HEAD पर रहते हुए submodule files edit करना और commits खो देना, जबकि आपको पहले एक branch checkout करना चाहिए।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: