Welcome back to CodeYourCraft! Today, we're diving into an exciting topic: Cloning with Submodules. This is a powerful Git feature that lets you include other repositories as part of your project. Let's get started!
Submodules are nested Git repositories that live within another Git repository. They allow you to keep track of multiple projects within one project, making it easier to manage dependencies.
Let's create a submodule for a popular library called awesome-library.
cd my-main-projectgit submodule add https://github.com/awesome-library/awesome-library submodules/awesome-libraryNow, awesome-library is a submodule of my-main-project.
To update a submodule, navigate to the submodule directory and use the git pull command:
cd submodules/awesome-library
git pull origin mainWhen you commit changes to your main project, Git will automatically include changes to the submodule as well. To manually commit a submodule change, use these commands:
cd submodules/awesome-library
git commit -am "Submodule changes"
cd ../..
git add submodules/awesome-library
git commit -m "Updated submodule"
git pushTo remove a submodule, use these commands:
cd submodules/awesome-library
git submodule deinit
cd ..
rm -rf submodules/awesome-libraryWhat is a submodule in Git?
That's it for today! In the next lesson, we'll explore how to initialize a submodule and manage its history. Until then, happy coding! 🤝🏼