Magento Contribution Day was conducted perfectly. The main topic of the event was addressed to the procedure of merge requests creation and to the knowledge mastering in real conditions. The task was to fix several confirmed code issues in the list on https://github.com/magento/magento2/issues. Participants of the Contribution Day were allowed to work with any issue from the list, they should fix it locally and submit merge request to the original Magento storage.
Magento Contribution Day gave me a clear picture of the way merge request should be created.
Here’s step-by-step instruction:
Magento 2 merge request: forked-storage creation
Sign in with your account on Github and move to the page of Magento 2 storage (https://github.com/magento/magento2), then press the button “Fork” in the right top corner.
You will see the image:
The newly created storage page (hereinafter called a forked-storage):
Pay attention to the title “forked from magento/magento2” (see the arrow on the screenshot). It means that the created storage has memory info about its original storage “magento/magento2”.
The memory info allows creating merge requests from your forked-storage to the original storage. The action described above has to be done just once. When it is done, you have your own forked-storage for further merge requests execution.
Merge request creation
You have to create a merge request when you want to add some changes or bug fixes into Magento code.
Your forked-storage may become not up-to-date (according to original storage “magento/magento2”) when you have the needing to add changes in the code. It isn’t a big problem. The purpose of your forked-storage isn’t a reflection of the original one. You may even delete some branches that appeared as a result of fork-process.
The goal of the forked-storage is that it allows making merge request from any branch to the needed branch of original storage.
Steps of merge request creation:
- clone your forked-storage from Github to your local memory disk;
- enable the original storage “magento/magento2” as a remote resource;
- create a new branch on the local disk, then put the code you’re going to change from the required branch of the original storage;
- add changes to the new branch on the local disk;
- do the push to the new branch to your forked-storage on Github;
- open github.com and create merge request to the needed branch of the original storage “magento/magento2”.
Explanations of the steps:
1. clone your forked-storage from Github to your local memory disk
There is nothing complicated with this step. Create an empty catalog on your local disk, open it and then run the command (the dot at the end means that the cloning will be done in the current catalog):
git clone https://github.com/example/magento2.git .
2. enable the original storage “magento/magento2” as a remote source
We need to get an ability to create new branches on the local disk. The branches have to be equal to the same branches from the original storage “magento/magento2”. For this purpose, we need to enable the original storage as a remote source. It can be done with the following command:
git remote add upstream https://github.com/magento/magento2.git
Use the following command to check if the source is added:
git remote -v
3. create a new branch on the local disk, then put the code you’re going to change from the required branch of the original storage
For example, I want to add changes to the branch 2.2-develop of the original storage “magento/magento2”.
Get the latest changes from the remote source (the one that we added):
git checkout upstream/2.2-develop -b abracadabra
Check if the new branch was successfully created and have become the current one with the following command:
git branch -l
4. add changes to the new branch on the local disk
Everything is easy with this step. Edit needed files and run the commands:
git add -A git commit -m "Some abracadabra changes to merge"
5. do the push to the new branch to your forked-storage on Github
A simple step as well as the previous one.
git push --set-upstream origin abracadabra
When this command is done, the work with a pc console is finished. Further, you need to go to github.com.
6. open github.com and create merge request to the needed branch of the original storage “magento/magento2”
Open the website, sign in and go to the page of your forked-storage. There should be the confirmation of successful adding of the branch abracadabra into the storage.
Press the button “Compare & pull request” to create merge request (see the arrow in the screenshot):
Then, there will appear the page with the information about the branch that should be merged:
Put required data attentively and confirm merge request. You should follow Magento rules strictly (it can be found easily on the web).
Ask questions and provide comments below!
Magento Developer at Mobecls
6+ years of experience
Feel free to ask me anything about this post in the comments below