Junior — Middle
What exactly happens in the system when performing a merge operation of two branches in Git?
sobes.tech AI
Answer from AI
When performing a merge operation of two branches in Git, changes from one branch (usually the target) are combined into the other (current). Git analyzes the common base (common ancestor) of both branches and compares the changes made in each. If there are no conflicts, Git automatically merges them, creating a new merge commit with two parents — pointing to the latest commits of both branches.
If changes affect the same parts of the code, a conflict arises, which must be resolved manually. After resolving conflicts, a merge commit is created.
Example command:
git checkout main
git merge feature-branch
Here, changes from the feature-branch will be merged into main.