Breaking Down Microservices from a Unified Git Repository
Scenario
Assume that we have 100 micro-services in a single repository. Developers have been working for three years, and there have been more than 2000 commits made in that single repository. Now, considering the best practices of DevSecOps, they want to split each single microservice into a repository.
Resolution
Step 1: Clone the parent repository in your local directory using a terminal.
git clone <parent-repo-url>
Step 2: You have to install a git-filter package in your local environment to achieve this because the native git commands will not support it.
Step 3: Install the package using the below commands
For yum packages,
sudo yum install python3-pip
pip3 install git-filter-repo
git filter-repo --version
For apt packages,
sudo apt-get install git-filter-repo
After executing these commands, you will be able to see the git filter-repo command working in your terminal
Step 4: Navigate to your cloned directory, execute the below command, and replace the path with the actual single micro-service path in your repository.
git filter-repo --path <your-path>
for example, if login is a service and it contains a directory, then
git filter-repo --path login/
This will remove additional folders or services from your local repository and gather all of those specific micro-service commits.
Step 5: Create a new repository and copy the git url (clone url)
Step 6: Set the remote repository URL in your local terminal, like in the below command.
git remote add <service-name> <new-repo-url>
Step 7: After adding the remote URL, push the code using the below command.
git push <service-name> <branch-name>
Replace the branch name with either master or main according to your git repository
Conclusion
Now, all of the commits for that specific service, along with your single microservice, are pushed to a new git repository. For each of your micro-services, repeat the procedure. Start the new procedure after removing the local clone of the parent repository.
Subscribe to my newsletter
Read articles from Jayakumar Sakthivel directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Jayakumar Sakthivel
Jayakumar Sakthivel
As a DevOps Engineer, I specialize in streamlining and automating software delivery processes utilizing advanced tools like Git, Terraform, Docker, and Kubernetes. I possess extensive experience managing cloud services from major providers like Amazon, Google, and Azure. I excel at architecting secure CI/CD pipelines, integrating top-of-the-line security tools like Snyk and Checkmarx to ensure the delivery of secure and reliable software products. In addition, I have a deep understanding of monitoring tools like Prometheus, Grafana, and ELK, which enable me to optimize performance and simplify cloud migration journeys. With my broad expertise and skills, I am well-equipped to help organizations achieve their software delivery and cloud management objectives.