0Pricing
Git Advanced: Monorepo, Submodules & Workflows · Ders

Alt Modül Ekleme ve Kopyalama

Bir projeye yeni alt modül ekleme ve alt modüller içeren bir depoyu doğru şekilde kopyalama komutlarını öğrenin.

Alt Modül Ekleme ve Kopyalama, CoddyKit'te ücretsiz bir Git Advanced: Monorepo, Submodules & Workflows dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Git Advanced: Monorepo, Submodules & Workflows öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Git Advanced: Monorepo, Submodules & Workflows kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Add & Clone Git Submodules

Git submodules let you embed one Git repository inside another. This is useful for managing external dependencies like libraries or shared components.

In this lesson, we'll learn how to add a new submodule to your project and how to properly clone a repository that contains submodules.

The `git submodule add` Command

To add a submodule, you use the git submodule add command. This command takes the URL of the external repository and optionally a local path where you want to place it.

  • Repository URL: The URL (HTTPS or SSH) of the submodule's Git repository.
  • Path: The directory within your main project where the submodule will reside. If omitted, Git uses the repository name.

Add Submodule in Action

Let's say you have a my-project repository and want to include a shared library from https://github.com/example/shared-lib.git.

First, navigate to your main project's directory.

cd my-project
git submodule add https://github.com/example/shared-lib.git lib/shared-lib

Files Created by `submodule add`

After running git submodule add, Git does a few things:

  • It clones the submodule repository into the specified path (e.g., lib/shared-lib).
  • It adds an entry to a special file called .gitmodules in your main repository's root.
  • It stages the new submodule directory and the .gitmodules file for commit.

Inspecting `.gitmodules`

The .gitmodules file is a configuration file that stores the mapping between the submodule's local path and its remote URL. It's crucial for others to clone your project correctly.

Here's what it might look like for our example:

[submodule "lib/shared-lib"]
	path = lib/shared-lib
	url = https://github.com/example/shared-lib.git

Commit Your Submodule Change

Adding a submodule is a change to your main repository, so you need to commit it. The commit will record the specific commit hash of the submodule's repository that your main project is currently using.

git status
git commit -m "Add shared-lib as a submodule"

Cloning a Parent Repository

When you clone a repository that contains submodules, Git clones the parent repository but doesn't automatically download the submodule content.

The submodule directories will appear empty or contain only a .git file pointing to the submodule's repository.

The Easy Way to Clone All

The most straightforward way to clone a repository and all its submodules is to use the --recurse-submodules flag with git clone.

This command clones the main repository and then automatically initializes and updates all submodules to their correct versions.

git clone --recurse-submodules https://github.com/your/my-project.git

Manually Initializing Submodules

If you forget --recurse-submodules during cloning, don't worry! You can initialize and update them manually after cloning the parent repository.

First, navigate into the cloned parent repository.

cd my-project
git submodule init

Fetching Submodule Content

After initializing, you need to tell Git to fetch the actual content for each submodule. This is done with the git submodule update command.

It fetches the data from the submodule's remote and checks out the specific commit recorded by the parent repository.

cd my-project
git submodule update

Check Your Submodule Knowledge

You've just cloned a repository named parent-repo which is known to contain a submodule. After cloning with just git clone parent-repo.git, what are the necessary commands to get the submodule's content ready for use?

Recap: Add & Clone Submodules

In this lesson, you learned how to:

  • Add a submodule using git submodule add <url> <path>, which creates a .gitmodules file and stages the submodule.
  • Commit submodule changes to record the specific version of the submodule in the parent repository.
  • Clone a repository with submodules using git clone --recurse-submodules for an all-in-one operation.
  • Manually initialize and update submodules with git submodule init and git submodule update if you cloned without the recurse flag.

Next, we'll explore how to manage and update submodules after they've been added and cloned.

Sıkça Sorulan Sorular

“Alt Modül Ekleme ve Kopyalama” dersi ücretsiz mi?

Evet — “Alt Modül Ekleme ve Kopyalama” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Git Advanced: Monorepo, Submodules & Workflows kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Git Advanced: Monorepo, Submodules & Workflows kursu toplamda 4 dersten oluşur.

“Alt Modül Ekleme ve Kopyalama” dersinde ne öğreneceğim?

Bir projeye yeni alt modül ekleme ve alt modüller içeren bir depoyu doğru şekilde kopyalama komutlarını öğrenin. Git Advanced: Monorepo, Submodules & Workflows ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Git Advanced: Monorepo, Submodules & Workflows öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Git Advanced: Monorepo, Submodules & Workflows, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.

“Alt Modül Ekleme ve Kopyalama” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Git Advanced: Monorepo, Submodules & Workflows dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Git Advanced: Monorepo, Submodules & Workflows dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Git Alt Modüllerine Giriş
  2. Alt Modül Ekleme ve Kopyalama
  3. Alt Modülleri Güncelleme ve Eşitleme
  4. Alt Modülleri Kaldırma ve Başlatmasını Sonlandırma
← Git Advanced: Monorepo, Submodules & Workflows Sayfasına Dön