|
| 1 | +--- |
| 2 | +title: "Handle Git conflicts via GitHub.Com" |
| 3 | +description: "How to handle git conflicts using the GitHub website" |
| 4 | +authors: [thierryo] |
| 5 | +date: 2024-04-17 |
| 6 | +categories: ["version control"] |
| 7 | +tags: ["git", "version control"] |
| 8 | +--- |
| 9 | + |
| 10 | +## Fix merge conflict with a pull request |
| 11 | + |
| 12 | +Sometimes a pull request warns about a merge conflict. |
| 13 | +A merge conflict occurs when one or more lines were altered in the base branch so that a merge conflict arises in the feature branch. |
| 14 | +The warning looks like the image below. |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +You can fix most merge conflicts in the browser. |
| 19 | +First push the `Resolve conflict` button in the warning. |
| 20 | +The website sends you to a page with a list of all merge conflicts. |
| 21 | +The webpage highlights them by a red vertical line. |
| 22 | +Every merge conflict inserts three delimiters: |
| 23 | + |
| 24 | +1. `<<<<<< feature branch name`: the start of the merge conflict |
| 25 | +1. `======`: the separator between the content of both branches |
| 26 | +1. `>>>>>> base branch name`: the end of the merge conflict |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +Fix the merge conflict by changing the source. |
| 31 | +Often you can fix it by simply deleting the content of one of the branches within the conflict. |
| 32 | +Potentially you need to keep a mix of both. |
| 33 | +Don't forget to also delete the three delimiters when you're ready. |
| 34 | +Should fixing the merge conflict be more complicated, then you probably better fix them via the [command line](../git_conflict/index.html). |
| 35 | +In our example we solved the conflict by keeping the content of the feature branch. |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | +Once you have fixed all merge conflicts, go to the top of the page. |
| 40 | +There hit the `Mark as resolved` button. |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +Finally you store the fixes in a new commit by hitting the `Commit merge` button. |
| 45 | + |
| 46 | + |
| 47 | + |
0 commit comments