The management of branches is used to manage several versions of the same application in parallel.
The most common case is as follows:
- You have deployed a version of your application and you are working on the next version of this application.
- Meanwhile, you would like to apply the bug fixes performed in the current version to the deployed version, and therefore create and deploy intermediate versions.
Branches are usually represented on a timeline.
In this example, there is a main branch (named "My Version") from which a "Version 1" branch has been created. The origin is the state of the project at the time the branch was created. This origin is noted in the branch: it will later allow an automatic merge.
In our example, changes have been made both in the main branch and in the "Version 1" branch. We want to reintegrate all the modifications of the main branch into "Version 1" by merging branches.
To perform this merge, three elements will be compared:
- The state of the project at the time the branch was created (origin).
- The current state of the main branch ("My Version").
- The current state of the "Version 1" branch.
By comparing the files in these three states, it is possible to calculate a merge of the two branches.
This merge is then reintegrated into the "Version 1" branch. Since the branches are now merged, the time of merging becomes the new origin that will be used for the next merge if necessary.