Git Merge Dry Run
This article will discuss git merge conflict resolution through the git command.
Overview of Git
Git has many functions that developers can easily use and solve their problems. Among these capabilities of git, Merging is the essential aspect that every developer needs while working in a big team on a single project.
It is the process of binding and branching history together on a single repository. It helps us link a couple of commits into a single unified branch history in a repository.
Git Merge Conflicts
During the conflicts of various commits, developers face some situations; when they merge their exact files and do different tasks while merging, a merge conflict occurs.
It will also occur when the developer simultaneously updates the local
repository file in several branches on a remote repository.
Merge conflict happens when any update or change is made to the same file on both branches or a single file with a conflict on the same line with a different team member’s code.
After this conflict, git has no idea which change to accept and which to refuse. The developer then must resolve it consciously because sometimes resolving it in the wrong way may lead to a severe problem for our project and delivery to the customer.
It can only be done smoothly with the support of teammates while working on a single project.
Use Dry Run to Avoid Merge Conflicts
We know that merge conflicts are widespread in a developer’s daily life; they face these problems now and then often. Still, developers do their best to resolve them as smoothly as possible to improve the productivity of the work.
There are many ways to resolve merged conflicts depending upon the condition of the conflict. Among them, one way to fix this is the dry run option of the merge, which we will discuss in the below region.
Git Merge Dry Run
Git has many commands that use the dry run option with them. The developer uses it to view what will happen but doesn’t apply it.
We can say that this is an option to verify what the git command is about to perform before doing that. While merging, we can also confirm that there are not any conflicts in this merge.
For doing so, we will use the following command with two flags for the dry run:
git merge --no-commit --no-ff <branch>
In the above command, the flags --no-commit
and --no-ff
is used to tell git to perform a merge but don’t commit the result to the repository and do not merge the commit with the previous commits.
If we commit and realize that we have made a mistake immediately after, we can quickly recover it using the git reset
command.
Abdul is a software engineer with an architect background and a passion for full-stack web development with eight years of professional experience in analysis, design, development, implementation, performance tuning, and implementation of business applications.
LinkedIn