Docs
Merge branches

Merge branches

Incorporate changes from one branch into another.

In software development, teams often work on new features or bug fixes in isolated branches. Once the work is complete and tested, it's important to integrate these changes back into the main codebase. Merging facilitates this integration without losing the history of changes.

Overview

The following is the process to execute a merge command in Y42:

Merge branches

Merging best practices

  • Keep your branch up-to-date with the main branch.

Regularly pull changes from the main branch into your working branch to ensure a simpler merge process and fewer conflicts.

  • Commit often.

This makes it easier to understand what changes led to a bug or conflict.

  • Write meaningful commit messages.

This helps others understand what changes were made and why. More on writing meaningful commit messages in this section.

Branch update notifications and one-click merge

When working on a branch in Git, staying up-to-date with the latest changes in the main branch is essential. Our new feature enhances this process by notifying you when your branch is behind and providing a simplified merge experience.

Notification when feature branch is behind main:

If your branch falls behind the main branch, you will receive an immediate notification. This notification is visually represented by a yellow icon, showing how many commits you are behind.

Feature branch behind main.Feature branch behind main.

Clicking on this icon allows you to merge the latest changes from the main branch into your feature branch with a single click.

Conflict indication

In cases where merging the main branch into your feature branch would result in conflicts, the notification icon turns red:

Feature branch conflict with main.Feature branch conflict with main.

Clicking on this red icon will prompt you to confirm the merge conflict resolution and choose which version to keep (incoming (main) or current).

Feature branch conflict resolution confirmationFeature branch conflict resolution confirmation
Feature branch conflict resolution.Feature branch conflict resolution.

Resolving merge conflicts

A merge conflict in Git arises when two branches have made changes to the same part of a file and Git cannot automatically reconcile the differences during a merge. This conflict results in Git marking the file as "unmerged," necessitating manual resolution. When a conflict occurs, Git outputs a message to indicate the issue, and the affected files are marked accordingly.

To manage these conflicts, open the marked files and look for the conflict markers (<<<<<<<, =======, and >>>>>>>). These markers delineate the differing segments of code. You'll need to manually edit the file to resolve these conflicts by choosing which changes to keep, modify, or remove, and then saving the file.

dim_products.sql

<<<<<< HEAD
CREATE TABLE dim_products AS SELECT * FROM products;
=======
CREATE TABLE dim_products AS SELECT * FROM staging.products;
>>>>>> conflicting-branch

All the lines between the <<<<<< HEAD and ======= exist in the current branch which the HEAD ref is pointing to.

All the lines betweeen ======= and >>>>>> conflicting-branch is content in the new branch that is trying to merge.

Once you've decided how to resolve each conflict, you can save the file, and commit it to complete the merge.

Resolve merge conflicts

FAQ

When should I merge branches?
What is a merge conflict?
How do I resolve a merge conflict?