---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.2
alternate:
  - https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/resolve-merge-conflicts.md
  - https://sourcecraft.dev/portal/docs/ru/sourcecraft/operations/resolve-merge-conflicts.md
  - href: en/sourcecraft/operations/resolve-merge-conflicts.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
title: How to resolve conflicts when merging branches in SourceCraft
description: Follow this guide to resolve conflicts that arise when merging branches in SourceCraft.
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt


# Resolving conflicts when merging branches

<!-- source: en/_includes/sourcecraft/git-conflicts.md -->
_Merge conflicts_ occur when [git](https://git-scm.com/) is unable to automatically merge changes from different branches. This happens when there are conflicting changes in the same places in the repository.

The causes of conflicts may include:
* Multiple users editing the same files at once.
* Pulling remote repository changes ([`git pull`](https://sourcecraft.dev/portal/docs/en/sourcecraft/tutorials/quickstart-git.md#fetch-repo)) that conflict with your local edits.
* Merging branches ([`git merge`](https://sourcecraft.dev/portal/docs/en/sourcecraft/tutorials/quickstart-git.md#merge-branch)) with conflicting changes made to the same lines of code.
* Pushing changes ([`git push`](https://sourcecraft.dev/portal/docs/en/sourcecraft/tutorials/quickstart-git.md#send-push)) to the remote repository that has commits conflicting with your local edits.

Types of conflicts:
* [Line update conflicts](#resolve-cli) are the most common type of conflict, which occurs when the same file line is updated differently in different branches.
* [File structure conflicts](#tree-conflicts) occur when one user updates a file and another user deletes it.

### What conflicts look like in files {#conflict-markers}

When `git` detects a conflict, it marks the problematic sections with special markers:

```text
Common part of the text before the conflict
<<<<<<< HEAD
Changes in the current branch
=======
Changes in the incoming branch
>>>>>>> branch-name
```

Where:
* `<<<<<<< HEAD` marks the beginning of changes in the current branch.
* `=======` is the separator between versions.
* `>>>>>>> branch-name` marks the end of changes in the incoming branch.

### Conflict resolution {#resolve}

{% list tabs group=instructions %}

- SourceCraft UI {#src}

  <iframe width="640" height="360" src="https://runtime.strm.yandex.ru/player/video/vplvor2l7ieyypvhqrjh?autoplay=0&mute=0" allow="autoplay; fullscreen; picture-in-picture; encrypted-media" frameborder="0" scrolling="no"></iframe>

  {% note warning %}

  Resolving [file structure conflicts](#tree-conflicts) is not available in the SourceCraft interface. To resolve such conflicts, use the command line or [SourceCraft Spaces](https://sourcecraft.dev/portal/docs/en/sourcecraft/concepts/spaces.md).

  {% endnote %}

  1. Open the [SourceCraft home page](https://sourcecraft.dev).
  1. On the ![image](../../_assets/console-icons/house.svg) **Home** tab, under ![image](../../_assets/console-icons/layout-tabs.svg) **Your craftspace**, navigate to ![image](../../_assets/console-icons/archive.svg) **Repositories**.
  1. Select a repository.
  1. Under ![image](../../_assets/console-icons/code.svg) **Code** on the repository page, go to ![image](../../_assets/console-icons/code-pull-request.svg) **Pull requests**.
  1. Select a pull request and click ![image](../../_assets/console-icons/code-pull-request.svg) **Merge** in the top-right corner.
  1. On the pull request page, review the conflict message, for example:

      ```text
      Merge blocked
      ...
      This branch has conflicts that must be resolved
      filename.js
      CONFLICT (content): Automatic merge failed to resolve conflict in filename.js; Manual content merge required
      ```

  1. Click **Resolve in UI**.
  1. This will open a code editor, where the conflicting sections will be marked with specials markers:

      ```text
       1    ...
       2    Common part of the text before the conflict
       3    ...
            [Accept current change] [Accept incoming change] [Accept both changes]
       4    <<<<<<< main
       5    Changes in the current branch
       6    =======
       7    Changes in the incoming branch
       8    >>>>>>> feature-branch
       9    ...
      10    Common part of the text after the conflict
      11    ...
      ```

      Where:
      * `Accept current change`, `Accept incoming change`, and `Accept both changes` are buttons for resolving an individual conflict.
      * `<<<<<<< main` marks the beginning of changes in the current branch.
      * `=======` is the separator between versions.
      * `>>>>>>> feature-branch` marks the end of changes in the incoming branch.

  1. Resolve the conflicts:

      * To resolve an individual conflict, next to the section in question, click:
          * **Accept current change**: Accept the changes from the current branch.
          * **Accept incoming change**: Accept the changes from the incoming branch.
          * **Accept both changes**: Accept the changes from both branches.

      * To resolve all conflicts, at the top right, click:
          * **Accept current**: Accept all changes from the current branch.
          * **Accept incoming**: Accept all changes from the incoming branch.

          {% note warning %}

          In this case, all changes will be merged even if you previously resolved individual conflicts differently.

          {% endnote %}

  1. Click **Mark as resolved** and **Commit changes**.

- Command line {#cli}

  1. Identify the files with conflicts by executing this command:

      ```bash
      git status
      ```

      Files with conflicts will be displayed marked with `both modified`.
  1. Open the file with the conflict in the text editor.
  1. Locate the conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`).
  1. Choose the conflict resolution option:
      * Delete the version you do not need.
      * Create new code to merge both versions.

      After the changes are introduced, remove all conflict markers.
  1. Save the file.
  1. Add the updated file into the index:

      ```bash
      git add <file_name>
      ```

  1. Finish the merge:

      ```bash
      git commit -m "Resolve merge conflict"
      ```

  1. Push the changes:
      
      ```bash
      git push
      ```

{% endlist %}

### File structure conflicts {#tree-conflicts}

To resolve a conflict when a file was updated in one branch and deleted in another:
1. Check the conflict status:

    ```bash
    git status
    ```

1. Choose the next action with the file:
    * To keep the file, run this command:

      ```bash
      git add <file_name>
      ```

    * To delete the file, run this command:

      ```bash
      git rm <file_name>
      ```

1. Finish the merge:

    ```bash
    git commit -m "Resolve file deletion conflict"
    ```

### Using merge tools {#merge-tools}

You can use graphical tools for convenient conflict resolution.
To start the configured merge tool, such as VS Code, Sublime Merge, or others, run this command:

```bash
git mergetool
```

### Aborting the merge {#abort-merge}

To abort the merge and revert to the state before the operation started, run this command:

```bash
git merge --abort
```
<!-- endsource: en/_includes/sourcecraft/git-conflicts.md -->

#### Useful links {#see-also}

* [Getting started with Git](https://sourcecraft.dev/portal/docs/en/sourcecraft/tutorials/quickstart-git.md)
* [Working with pull requests in SourceCraft](https://sourcecraft.dev/portal/docs/en/sourcecraft/operations/pr-work.md)
* [Official Git documentation on conflict resolution](https://git-scm.com/docs/git-merge#_how_to_resolve_conflicts)
