Book Image

Git Best Practices Guide

By : PIDOUX Eric
Book Image

Git Best Practices Guide

By: PIDOUX Eric

Overview of this book

Table of Contents (12 chapters)

Managing Git submodules


You will probably work on a project that requires dependency on another project. This can be a library that was developed by you or another team. It can be hard to manage when the library is updated and you made some custom code inside your project.

Git handles this by using submodules. It allows you to manage a Git repository as a subfolder of another Git repository, which in turn lets you clone a repository isolated from the commits of the current repository.

Adding a submodule

Let's imagine you are working on a website and you want to add the fpdf library that helps you create a PDF file in PHP. The first thing to do is to clone the library's Git repository inside your subfolder:

Erik@server:~/mySite/$ git submodule add https://github.com/lsolesen/fpdf.git fpdf
Cloning in 'fpdf'
remote: Counting objects: 966, done.
remote: Total 966 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (966/966), 5.96 MiB | 1.13 MiB/s, done.
Resolving deltas: 100% (292/292), done...