How to resolve merge Conflict in git ?
Tags: git, github, javascript, beginners
Published: 2022-08-07 21:02:00

![git image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i4zncxo11oh91o1nj33a.png)
 



<h3> Table of contents</h3>
<ul>
<li><a href="#1">what is git?</a></li>
<li><a href="#2">why git?</a></li>
<li><a href="#3">basic git command</a></li>
<li><a href="#4">type of git merge conflict</a></li>
<li><a href="#5">how to resolve merge conflict in git?</a></li>
<li><a href="#6">git commands to resolve conflicts </a></li>
<ul>


<h2 id="1">What is Git?</h2>
Git is an open-source, distributed version control system (VCS) designed to handle everything from small to very large projects with speed and efficiency, which has a remote repository on the server-side and a local repository on the client-side. This means that the file or code is not present on a central server but there is a copy of the file stored on the client’s computer.


<h2 id="2"> why git?</h2>
Simply put, Git is a version control system that lets you manage and keep track of your source code history. GitHub is a cloud-based hosting service that lets you manage Git repositories. If you have open-source projects that use Git, then GitHub is designed to help you better manage them.

<h2 id="3"> Basic Git Commands </h2>

```

- git config 
- git init
- git add . 
- git diff
- git commit
- git reset
- git status
- git merge
- git push
- git pull
```

<h2 id="4"> What is a Git Merge Conflict?</h2>
A merge conflict is an event that takes place when Git is unable to automatically resolve differences in code between two commits. Git can merge the changes automatically only if the commits are on different lines or branches.

<h2 id="5">Types of Git Merge Conflicts </h2>
There are two points when a merge can enter a conflict state: 

1.  Starting the Merge Process If there are changes in the working directory’s stage area for the current project, merging won’t start. In this case, conflicts happen due to pending changes that need to be stabilized using different Git commands.

2.  During the Merge Process The failure during the merge process indicates that there is a conflict between the local branch and the branch being merged. In this case, Git resolves as much as possible, but there are things that have to be resolved manually in the conflicted files. We will now go over resolving merge conflicts in Git.

<h2 id="6"> How to Resolve Merge Conflicts in Git?</h2>
There are a few steps that could reduce the steps needed to resolve merge conflicts in Git.

1. The easiest way to resolve a conflicted file is to open it and make any necessary changes

2. After editing the file, we can use the git add command to stage the new merged content.

3. The final step is to create a new commit with the help of the git commit command. 

4. Git will create a new merge. commit to finalize the merge

<h2 id=""> Git Commands to Resolve Conflicts</h2>

1. The git log --merge command helps to produce the list of commits that are causing the conflict.
>

```
 git log --merge

```
2. The git diff command helps to identify the differences between the states repositories or files.
> 

```
git diff 
```

3. The git checkout command is used to undo the changes made to the file, or for changing branches
>

```
 git checkout 
```

4. The git reset --mixed command is used to undo changes to the working directory and staging area
>

```
 git reset --mixed 

```
5. The git merge --abort command helps in exiting the merge process and returning back to the state before the merging began.
>

```
git merge --abort

```
6. The git reset command is used at the time of merge conflict to reset the conflicted files to their original state
> 

```
git reset
```