Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 0 additions & 12 deletions .github/steps/1-create-a-pr.md

This file was deleted.

49 changes: 49 additions & 0 deletions .github/steps/1-step.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## Step 1: Learn about merge conflicts

### What is a merge conflict?

A **merge conflict** occurs when changes are made to the same part of the same file on two different branches.

```mermaid
gitGraph
checkout main
commit id: "Initial"
commit id: "Add resume.md"

branch my-resume
checkout my-resume
commit id: "Update skills"

checkout main
commit id: "Also update skills"

checkout my-resume
commit id: "Other changes"

checkout main
merge my-resume id: "Conflict!"
```

**What's happening here:**

1. We start with a repository and add a `resume.md` file.
2. We create a new branch called `my-resume` and update the skills area.
3. At the same time, someone else also updates the skills area on the `main` branch.
4. We add other unrelated changes to the `my-resume` branch.
5. When we try to merge `my-resume` into `main`, we get a **conflict!** Both branches modified the same part of `resume.md`.

### ⌨️ Activity: Create a pull request

To quickly practice, we already created the above scenario for you by making a new branch `my-resume` then modifying `resume.md` on both branches, which will will cause a conflict. Let's practice with it!

1. Open this repo in a new browser tab, and work on the steps in your second tab while you read the instructions in this tab.

1. In the top navigation, select the **Pull requests** tab.

1. Click the **New pull request** button and use the following settings:

- Base: `main`
- Compare: `my-resume`
- Title: `Resolve a merge conflict`

1. With the new pull request opened, Mona will share the next steps.
21 changes: 0 additions & 21 deletions .github/steps/2-resolve-a-merge-conflict.md

This file was deleted.

80 changes: 80 additions & 0 deletions .github/steps/2-step.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
## Step 2: Resolve a merge conflict

Managing conflicts can be intimidating, but have no fear, Git is smart with merging! Git only needs a human to decide when the situation is very unclear.

You typically have 3 options for managing a conflict:

1. Accept the version from the base branch.
1. Accept the version from the compare branch.
1. Manually combined the changes from both branches.

> [!TIP]
> You can learn more about managing conflicts on the [GitHub Docs: resolve the conflict](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line) page.

### When should I resolve a conflict?

Conflicts can be resolved as soon as they are noticed. Resolving a conflict doesn't automatically merge the pull request in GitHub. Instead, it stores the conflict's resolution as a **reverse merge** commit, allowing you to keep working on your branch as normal.

This means that some changes from the `base` branch (`main`) are merged into the `compare` branch (`my-resume`). Only the `compare` branch is updated, which allows you to test the resolved changes before merging.

```mermaid
gitGraph
checkout main
commit id: "Initial"
commit id: "Add resume.md"

branch my-resume
checkout my-resume
commit id: "Update skills"

checkout main
commit id: "Also update skills"

checkout my-resume
commit id: "Other changes"

checkout my-resume
merge main id: "Resolve conflict"
commit id: "Continue work"

checkout main
merge my-resume id: "Success!"

```

### ⌨️ Activity: Resolve a merge conflict

1. If needed, open the recently created pull request.

1. Scroll to the bottom of the page. Near the merge button, notice a message indicating there are conflicts to be resolved.

1. Press the **Resolve conflicts** button to open a special text editor for handling merge conflicts.

1. Look for a highlighted section similar to the below, which shows both versions of the conflict.

```txt
<<<<<<< my-resume
- Contributed to open source projects
=======
- Built internal tools
>>>>>>> main
```

1. After some inspection, we decide to keep the version from the compare branch. Remove the base branch version by deleting then content between `=======` and `>>>>>>> main`.

```txt
<<<<<<< my-resume
- Contributed to open source projects
=======
>>>>>>> main
```

1. With our manual changes finished, let's remove the merge conflict markers. Only the content from the compare branch will remain.

```txt
- Contributed to open source projects
```

1. In the top right, click the **Mark as resolved** button and choose **Commit merge**.

1. With the conflict resolved, Mona will share the next steps.
21 changes: 0 additions & 21 deletions .github/steps/3-create-your-own-conflict.md

This file was deleted.

12 changes: 12 additions & 0 deletions .github/steps/3-step.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Step 3: Merge your pull request

Nice work! All that remains is to merge!
Yep, that's it! Merge conflicts can be easy! 🥰

### ⌨️ Activity: Merge your pull request

1. Click the **Merge pull request** button.

1. (optional) Delete the branch `my-resume`.

1. With the pull request merged, Mona will share a final review then update the readme to share your success. Nice work! 😎
13 changes: 0 additions & 13 deletions .github/steps/4-merge-your-pull-request.md

This file was deleted.

19 changes: 0 additions & 19 deletions .github/steps/X-finish.md

This file was deleted.

20 changes: 20 additions & 0 deletions .github/steps/x-review.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Review

<img src=https://octodex.github.com/images/benevocats.jpg alt=celebrate width=300 align=right>

Congratulations! You've successfully completed the **Resolve Merge Conflicts** exercise. 🎉

You've learned essential skills for collaborative development on GitHub:

- **Understanding merge conflicts**: You now know why conflicts occur when multiple people edit the same file
- **Identifying conflicts**: You can recognize when GitHub detects merge conflicts in pull requests
- **Resolving conflicts**: You've practiced using GitHub's web editor to manually resolve conflicts by choosing which changes to keep
- **Merging successfully**: You completed the workflow by merging your pull request after resolving conflicts

### What's next?

Check out other [GitHub Skills exercises](https://learn.github.com/skills).

- [GitHub Pages](https://github.com/skills-dev/github-pages) - Publish your own static website for free.
- [Communicate using Markdown](https://github.com/skills-dev/communicate-using-markdown) - Improve your documentation skills
- [Getting Started with GitHub Copilot](https://github.com/skills/getting-started-with-github-copilot) - Learn, build, debug and ship faster with an AI pair programmer.
43 changes: 21 additions & 22 deletions .github/workflows/0-start-exercise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ permissions:
issues: write

env:
STEP_1_FILE: ".github/steps/1-create-a-pr.md"
STEP_1_FILE: ".github/steps/1-step.md"

jobs:
start_exercise:
if: |
!github.event.repository.is_template
name: Start Exercise
uses: skills/exercise-toolkit/.github/workflows/start-exercise.yml@v0.5.0
uses: skills/exercise-toolkit/.github/workflows/start-exercise.yml@v0.7.0
with:
exercise-title: "Resolve Merge Conflicts"
intro-message: "Let's learn how to resolve merge conflicts when collaborating on GitHub."
Expand All @@ -27,8 +27,6 @@ jobs:
name: Prepare merge conflict
runs-on: ubuntu-latest
needs: [start_exercise]
env:
ISSUE_URL: ${{ needs.start_exercise.outputs.issue-url }}

steps:
- name: Checkout
Expand All @@ -43,24 +41,25 @@ jobs:
git config user.email github-actions[bot]@users.noreply.github.com
echo "- Contributed to open source projects" >> resume.md
git add resume.md
git commit -m "Add open source contribution"
git commit -m "Add open source experience"
git push origin my-resume

git checkout main
git pull --rebase origin main
echo "- Built internal tools at Acme Corp" >> resume.md
echo "- Built internal tools" >> resume.md
git add resume.md
git commit -m "Add Acme Corp experience"
git commit -m "Add internal experience"
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

post_next_step_content:
name: Post next step content
runs-on: ubuntu-latest
needs: [start_exercise, prepare_merge_conflict]
needs: [start_exercise]
env:
ISSUE_URL: ${{ needs.start_exercise.outputs.issue-url }}
ISSUE_NUMBER: ${{ needs.start_exercise.outputs.issue-number }}
ISSUE_REPOSITORY: ${{ github.repository }}

steps:
- name: Checkout
Expand All @@ -71,24 +70,24 @@ jobs:
with:
repository: skills/exercise-toolkit
path: exercise-toolkit
ref: v0.5.0
ref: v0.7.0

- name: Create comment - add step content
run: |
gh issue comment "$ISSUE_URL" \
--body-file "$STEP_1_FILE"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: GrantBirki/[email protected]
with:
repository: ${{ env.ISSUE_REPOSITORY }}
issue-number: ${{ env.ISSUE_NUMBER }}
file: ${{ env.STEP_1_FILE }}

- name: Create comment - watching for progress
run: |
gh issue comment "$ISSUE_URL" \
--body-file "exercise-toolkit/markdown-templates/step-feedback/watching-for-progress.md"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: GrantBirki/[email protected]
with:
repository: ${{ env.ISSUE_REPOSITORY }}
issue-number: ${{ env.ISSUE_NUMBER }}
file: exercise-toolkit/markdown-templates/step-feedback/watching-for-progress.md

- name: Enable next step workflow
run: |
gh workflow enable "Step 1"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading
Loading