Managing your Magento 2 code based on git repository

This article is related to source code management of Magento 2. We understand that you already setup your magento store. If not then please take a look of Technical Specification and kick off details for Magento 2
If you are thinking to start a new magneto 2 project then the very first thing you should think about, the best code management technique. We will learn best Q & A related to your Magento 2 code repository including the benefits of using proper code repository.

Why code repository for your project is important?

If you wanted to start creating a website with multiple team members. The first thing you should do is to create a repository architecture which is very important for successful project delivery. Below are some advantages of using proper code management :-

  • Any new team member can quickly onboard
  • Core magento can be easily upgraded
  • Custom module and theme should easily be managed and kept secure
  • Easy to manage application even from deployment perspective

Best practices for managing code within source repository

Based on use case there could be two options to manage project.
i) Use whole code under only one git branch (Use case 1: if you have only few team members and small project)
ii) Use two different branch, one branch to store core code and another branch to store customized code including UI changes. (Use case 2: more team members and more customization)
What about DB (Should we really put db under repository?)
Some teams also export db in a zip file and put that inside the git only. But its not always recommended practice. We should think / will need to create a process for sharing database files in order to create cloned environments as needed for development and testing. We can create two set of database dumps i) will be used for dev/testing ii) another for staging server (which is just a copy of production)

How to onboard a teammate with this architecture

  • Fork core repository
  • Clone custom repository
  • Add media, env.php
  • Install db on your machine (of any server)
  • Regenerate other files

How to update core repository

  • Fork the repository.
  • Make the fix (update the core )
  • Submit a pull request to the project owner.

What all things we shouldn’t keep in git

  • env.php
  • Media
  • Generation files under var (or we should keep var folder with only few files)

Branching structure and Environments

  • Development
  • Staging
  • Production
  • Apart from that we should also create temporary branch which will get updated/merged from main branch
The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video Conferencing and social media domain. The motive of creating cutehits was just to share the knowledge/solutions I get to know during my day to day life so that if possible I can help someone for same problems/solutions. CuteHits.com is a really a very effort for sharing knowledge to rest of the world. For any query/suggestion about same you can contact me on below details:- Email: shekharmca2005 at gmail.com Phone: +91-9560201363

Latest posts by Chandra Shekhar (see all)

You may also like...