📜 ⬆️ ⬇️

Organization of work with git submodules

When I started working with git, I almost immediately had a question - how to work with a project if some of its components are updated frequently. A prime example is the development using Symfony2 . The framework is updated almost every day, you need to constantly “pull up” the code so that it works with the latest version of Symfony2.

Under the cut a small workflow for working with a project on Symfony2.

A couple of days ago, Symfony2 moved to PR3 . In this regard, I immediately wanted to play around with the latest version of symfony-sandbox , sharpened for PR3. I want to get a working sandbox with a link to the framework symfony2 and keep it up to date by updating the framework separately.
')
First, download the current version of symfony-sandbox (PR3 branch is needed):
git clone -b PR3 github.com/symfony/symfony-sandbox.git symfony2sandbox
Next, we want the framework to connect as a link. That is, it can be updated independently. There are a lot of advantages in this - the main one is that the project can be divided into independent bundles that are developed and tested independently of the projects that use them. When developing with submodules, you can make it so that different projects will use different versions of bundles. If to speak more simply - projects become small, as if consisting of large bricks, they are easier to maintain.

In order to see how this development will look something like: miam project - in the vendors folder there are plug-in frameworks that live independently of the current project, so they are connected as submodules.

We do it on the principle of a guide on working with submodules on github .

That's all - now we have a well-formed project in which the code of independent components is clearly separated from the code of this project. Now a couple of tricks to work with our project.

1) Suppose we have free time and we want our project to work with the latest version of the submodule:

Go to the submodule directory
cd src/vendor/symfony/
We update the submodule
git checkout -f
After that, we run unit tests, and ensure that they are all "green."

2) Suppose someone wants to deploy your project in your local directory:

First clone the project
git clone ... [your_project.git]
If we now go into the submodule directories, we find that they are empty. To restore a complete project, you need to clone the required versions of the submodules. Go to the root of the project and run the command.
git submodule update --init

That's all, pleasant development. A lot of obvious things, but also post something small.

Source: https://habr.com/ru/post/60860/


All Articles