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?
- 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
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
- Generation files under var (or we should keep var folder with only few files)
Branching structure and Environments
- Apart from that we should also create temporary branch which will get updated/merged from main branch
Latest posts by Chandra Shekhar (see all)
- Best practices for micro service design - January 23, 2022
- Spring Boot - January 23, 2022
- Java - January 23, 2022