Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions git/git-essentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,53 @@ git push origin <your branch name>
<img src="images/git-push.gif?raw=true" alt="" />
</p>

## How to solve a Merge Conflict

Merge conflicts occur when competing changes are made to the same line of a file, or when one person edits a file and another person deletes the same file.

To resolve a merge conflict caused by competing line changes, you need to choose which changes you want to incorporate and make a new commit.

The merge conflict error will be shown to you when you try to merge two branches and the aforementioned competing changes exist.

You can solve the conflict like this:

1. Navigate to the repository with the conflict in your terminal.

2. Check which files are affected with the git status command.

```bash
$ git status
> # On branch branch-b
> # You have unmerged paths.
> # (fix conflicts and run "git commit")
> #
> # Unmerged paths:
> # (use "git add ..." to mark resolution)
> #
> # both modified: styleguide.md
> #
> no changes added to commit (use "git add" and/or "git commit -a")
```

3. Open the conflicted file in a text editor.

4. To see the beginning of the merge conflict in your file, search the file for the conflict marker <<<<<<<. When you open the file in your text editor, you'll see the changes from the HEAD or base branch after the line <<<<<<< HEAD. Next, you'll see =======, which divides your changes from the changes in the other branch, followed by >>>>>>> BRANCH-NAME. In this example, one person wrote "open an issue" in the base or HEAD branch and another person wrote "ask your question in IRC" in the compare branch or branch-a.

```bash
If you have questions, please
<<<<<<< HEAD
open an issue
=======
ask your question in IRC.
>>>>>>> branch-a
```

5. Decide if you want to keep only your branch's changes, keep only the other branch's changes, or make a brand new change, which may incorporate changes from both branches. Delete the conflict markers <<<<<<<, =======, >>>>>>> and make the changes you want in the final merge.

6. Add and commit your changes.

Now you can push your changes to your remote repository.

## Create a Pull Request

Once you pushed your working branch, you need to make a pull request against `master`. by visiting the repo's GitHub page and clicking on the green `Compare and pull request` button:
Expand Down