0Pricing
Git Advanced: Monorepo, Submodules & Workflows · Урок

Работа с ветками подмодулей

Научитесь управлять ветками внутри подмодуля, переключаться между ними и отправлять изменения в исходный репозиторий подмодуля

«Работа с ветками подмодулей» — бесплатный урок 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 status

Checking 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 -1

Switching 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-feature

Committing 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-feature

Updating 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 main

Submodule 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 main branch 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 включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Работа с ветками подмодулей
  2. Вложенные подмодули и сложные конфигурации
  3. Распространённые проблемы подмодулей и их исправление
  4. Закрепление подмодулей за определёнными тегами и коммитами
← Назад к Git Advanced: Monorepo, Submodules & Workflows