Blogs

Home / Blogs / How to Resolve Merge Conflicts in Git

Table of Content
The Automated, No-Code Data Stack

Learn how Astera Data Stack can simplify and streamline your enterprise’s data management.

    How to Resolve Merge Conflicts in Git

    September 3rd, 2024

    The ability to have multiple team members contribute to a project and drive it to completion in time is invaluable for a product’s success, especially when it gets regular feature updates and enhancements based on customer feedback. Teams easily achieve this concurrent contribution through distributed version control systems (DVCS) like Git.

    The fact that Git operates on a distributed repository model means that the source code and its entire version history are available to every developer enabling them to revert and “go back in time.” Team members working on the same project can work in different branches, which they later merge.

    But what happens when two developers working on the same file make changes, commit, and push those changes? Or if those developers work in different branches of the same repository, and one decides to merge the branches? The answer is simple: both scenarios will cause a Merge Conflict.

    In this blog, we will learn how to resolve merge conflicts in Git from within Astera’s Data Platform. But before that, let’s quickly go through what conflicts are and why they occur.

    What are Merge Conflicts in Git?

    Under normal circumstances, i.e., when commits are on two different lines of code or branches, Git resolves the differences automatically. However, when the differences are in the same lines of code, Git requires human intervention to resolve these differences. This instance, where it cannot resolve differences on its own, is called a merge conflict, or simply, a conflict.

    The following image illustrates how a conflict can occur:

    How to resolve merge conflict in git

    Merge conflict

    Let’s say there are two developers, A, and B, working in the same branch. Both these developers pull the same file from the remote repository and make changes to it. Developer B completes his task earlier and pushes the file back to the server. So far, so good.

    Similarly, Developer A completes her job and proceeds to push it. However, she faces a conflict when she tries to push the file. This conflict is because the same file has already been replaced in the remote repository with an updated version from Developer B’s end.

    The same would have happened if both these developers, working in different branches, had made changes to the same file, and one of them tried to merge their branch into the other developer’s branch. Yet another conflict will occur when one of the developers edits a file and the other deletes it.

    The developer who performs the merge operation is affected by the merge conflict; other team members will remain unaware unless they are explicitly made aware of it. Therefore, it is the responsibility of the developer to resolve the conflict and complete the merge process.

    How to Resolve Merge Conflicts in Git?

    The most common method to resolve a merge conflict is opening the file and manually making the required changes. For example, let’s say there’s a text file called “conflict.txt” that has recently been changed and needs to be pushed to the remote repository. However, the file does not get through as a conflict causes the merge process to stop.

    In this case, you will have to use the Git command line tools to resolve the conflict. You will likely go through the following steps in doing so:

    • Open the file in your preferred text editor
    • Identify the changes causing the conflict and make necessary changes
    • Use “git add conflict.txt” to stage the file
    • Use “git commit -m ‘your commit message here’” to commit

    Other Git commands that help resolve merge conflicts include:

    • git reset
    • git diff
    • git push
    • git merge –abort
    • git reset –mixed
    • git checkout
    • git status
    • git rebase –continue

    Resolving Merge Conflicts in Git from within Astera’s UI

    Astera’s Git integration offers a native version control solution that allows you to handle all your data management projects with ease. With Astera’s implementation of Git, a conflict can occur when two branches have a file with the same name and one of the branches is merged into the other.

    Similarly, you will face a conflict when there are differences in the files that have the same names in your local repository and the remote server.

    Let’s take an example to understand how you can face a conflict and what you need to do to resolve it while using Git via the Astera Data Platform. Say we have two local branches: Branch01 and Branch02.

    How to resolve merge conflict: Git Branches

    Git Branches browser in Astera

    Each branch has different data pipelines, but the files they are saved in contain the same name, “GitDataflow01”. See the images below:

    Image showing contents of Branch01 along with Git commands in Astera's UI

    Git Branches – Dataflow in Branch01 saved in file “GitDataflow01”

    Image showing contents of Branch02 along with Git commands in Astera's UI

    Git Branches – Dataflow in Branch02 saved in file “GitDataflow01”

    If we try and merge Branch01 into the current branch (Branch02 in this case), we will get an error due to the conflict, and the conflicted file will appear under a new node called Conflicted in the Git Changes window. So now we have a conflict, and before proceeding, we’ll have to resolve it.

    Let’s see how we can do that from within Astera’s UI. Keep in mind, though, that at this point, we have three options:

    • Abort merge process
    • Preview the files in each branch, or
    • Proceed with resolving without previewing (in case you are certain which version you want to keep)

    To resolve this conflict, right-click on the file, GitDataflow01 in this case, and expand the Resolve option to choose from Keep Current (Local) or Take Incoming (Remote). As the names suggest, selecting the former option will only keep the file version from the current branch (Branch02), while choosing the latter option will only keep the version from the branch that’s being merged (Branch01).

    How to resolve merge conflicts in git

    Resolving merge conflicts in Git within Astera’s UI

    Next, we will commit and provide a summary to complete the merge process.

    Astera’s Git integration allows you to perform most Git operations, such as push, pull, merge, fetch, commit, etc., without writing codes. You also get the option to use the command line interface if you are comfortable with it. Not only does it keep the version control management simple, but it also speeds up the entire process.

    With Astera’s Git integration, you get the best of both worlds to streamline your data management projects: Astera’s unified, no-code data management platform and Git’s superfast version control capabilities. Now that you know how to resolve merge conflicts in Git, take the next step and try it out yourself! Sign up for a 14-day free trial or schedule a demo today!

    Authors:

    • Khurram Haider
    You MAY ALSO LIKE
    Git Integration: Streamline your Data Projects with Astera
    How AI is Changing the Data Integration Process 
    Considering Astera For Your Data Management Needs?

    Establish code-free connectivity with your enterprise applications, databases, and cloud applications to integrate all your data.

    Let’s Connect Now!
    lets-connect