How to handle monolith repositories using git sparse checkout? (Git)

Harsh Vardhan Gautam
2 min readFeb 25, 2023

--

Have you ever worked on a monolith project? If yes, you may have already faced a situation where you’re working on one particular part of that monolith project and you literally don’t need to touch any other part of the project. In that case, it is very general that we will clone the whole monolith project and then work on our part but why cloning the whole project unnecessary?

To know the efficient solution for the problem discussed above, please continue reading the article.

Today, we’ll learn about git sparse-checkout command.

This command is used to create sparse checkouts, which change the working tree from having all tracked files present to only having a subset of those files.

Let us understand this with the help of a simple example. Let’s take the below scenario.

Image showing directory structure of project

Now, let’s say a team of web developers is there and they just have to work with web directory of the project. But if they go by usual way, then they will be cloning and working on the entire project including the mobile directory as well.

So, now we understood clearly that what we want to achieve here is to just work on the part of project which is meant there for your team. Basically, in the above example, web team wants to contribute on the project root_dir but now let’s see how web team will clone the project in an efficient way using git sparse-checkout.

  1. Firstly, to clone a repository in sparse mode by using this command.
git clone --no-checkout <url-to-your-repository>

2. Then, initialise the git sparse-checkout using below command.

git sparse-checkout init --cone

3. Thereafter, set the directories which you’re interested to work with like this. For example, as member of web team, I want to contribute in web directory.

git sparse-checkout set web
Image showing the effect of git sparse-checkout command

Yes. It is this simple. Now, if you check your project directory, see how sparse it looks, right? Only those directories are there which you actually work with. Nothing more than that, isn’t it great? Isn’t it magical?

That’s it !!!

Thank you for reading the whole article. I hope that the article has added some value to your time spent. I also appreciate your decision to learn something new today. Keep learning, keep growing.

I would love to hear feedback from my audience. Let me know your thoughts and suggestions in the comments.

Thank You!

--

--