العمل مع فروع الوحدات الفرعية
تعلّم إدارة الفروع داخل وحدة فرعية والتبديل بينها ودفع التغييرات إلى مستودعها الأصلي.
العمل مع فروع الوحدات الفرعية درس مجاني في Git Advanced: Monorepo, Submodules & Workflows على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Git Advanced: Monorepo, Submodules & Workflows، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Git Advanced: Monorepo, Submodules & Workflows 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Branching in Submodules
Git submodules usually point to a specific commit. But what if you need to actively develop inside a submodule?
- This allows independent feature development.
- You can contribute changes back to the submodule's own project.
- It's key for complex projects needing tight integration.
Submodules: Detached HEAD
By default, when you clone a project with submodules, each submodule is checked out to a specific commit. This is called a "detached HEAD" state.
- It means you're not currently on any named branch.
- You can view files, but new commits won't automatically belong to a branch.
- It provides a stable way for the parent repo to reference specific submodule versions.
Navigating into a Submodule
To work with a submodule's branches, you first need to navigate into its directory. Think of it as entering a completely separate Git repository.
Use the cd command to change directories:
# Assume 'my-submodule' is a submodule
cd my-submodule
git statusChecking Submodule Status
Once inside the submodule's directory, you can use regular Git commands to see its status, branches, and current HEAD. This helps you understand its current state.
# Inside the submodule directory
git status
git branch
git log --oneline -1Switching Submodule Branches
To develop within a submodule, you need to switch from a detached HEAD to a specific branch. Use git checkout just like in any other Git repository.
# Inside the submodule directory
git checkout main
# Or to create and switch to a new branch
git checkout -b new-featureCommitting in a Submodule
Now that you're on a branch, you can make changes, add them, and commit them. These commits are specific to the submodule's repository, not the parent repository.
# Inside the submodule directory
echo "New content" > newfile.txt
git add newfile.txt
git commit -m "Added newfile in submodule"Pushing Submodule Changes
After committing changes within the submodule, you need to push them to the submodule's own remote repository. This makes your changes available to others.
# Inside the submodule directory
git push origin main
# Or to push a new branch
git push origin new-featureUpdating the Parent Repository
After pushing changes in the submodule, the parent repository still points to the old commit. You need to tell the parent repo to track the new commit.
- Navigate back to the parent repository.
- Stage and commit the submodule's change.
# Back in the parent repository
cd .. # Go up one level
git status
git add my-submodule
git commit -m "Updated my-submodule to latest commit"
git push origin mainSubmodule Branching Tips
Working with submodule branches requires care and coordination:
- Communicate: Inform your team if you're actively developing on a submodule branch.
- Keep parent updated: Always commit the submodule reference change in the parent repo after pushing submodule changes.
- Avoid direct pushes: Don't push to a submodule's
mainbranch from the parent repo unless absolutely necessary; work inside the submodule itself.
Submodule Branch Quiz
Test your knowledge on managing submodule branches!
Recap: Submodule Branches
In this lesson, we explored how to actively develop within a Git submodule:
- Navigating into the submodule's directory.
- Switching from a detached HEAD to a specific branch.
- Making, committing, and pushing changes in the submodule.
- Updating the parent repository's reference to the new submodule commit.
This workflow enables independent development and contribution to submodule projects, making your overall project more flexible.
الأسئلة الشائعة
هل درس «العمل مع فروع الوحدات الفرعية» مجاني؟
نعم — نص درس «العمل مع فروع الوحدات الفرعية» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Git Advanced: Monorepo, Submodules & Workflows، انتقل إلى CoddyKit PRO. تتضمن دورة Git Advanced: Monorepo, Submodules & Workflows 4 دروس في المجموع.
ماذا ستتعلم في «العمل مع فروع الوحدات الفرعية»؟
تعلّم إدارة الفروع داخل وحدة فرعية والتبديل بينها ودفع التغييرات إلى مستودعها الأصلي. تتمرن على Git Advanced: Monorepo, Submodules & Workflows مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Git Advanced: Monorepo, Submodules & Workflows؟
لا تُشترط خبرة سابقة. Git Advanced: Monorepo, Submodules & Workflows على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «العمل مع فروع الوحدات الفرعية»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Git Advanced: Monorepo, Submodules & Workflows هذا؟
نعم. كل درس في Git Advanced: Monorepo, Submodules & Workflows يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- العمل مع فروع الوحدات الفرعية
- الوحدات الفرعية المتداخلة والإعدادات المعقدة
- مشكلات الوحدات الفرعية الشائعة وإصلاحاتها
- تثبيت الوحدات الفرعية على وسوم والتزامات محددة