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

Related posts:

The following two tabs change content below.

Chandra Shekhar

Consultant at Infogain
Chandra Shekhar is a LAMP Developer,Thinker,Blogger and currently working as Magento(Ecommerce) specialist.. I am always open to learn new things in LAMP as well as other newer technology. In the journey of my last 9 years of web and product development, I have decided to share my knowledge and experience to Open Source Community in 2011. In this regard I have started Since then I am actively sharing my knowledge on various LAMP technology through’s technical ... Read More about Chandra Shekhar

Latest posts by Chandra Shekhar (see all)