top of page

Resolving Merge Conflicts

Objective: The objective of this assignment is to provide hands-on experience in resolving merge conflicts in Git. You will encounter a merge conflict scenario, learn how to resolve it, and successfully complete the merge process.


Instructions:


Part 1: Repository Setup 


1. Task 1: Create a new directory/folder on your computer for this assignment and name it "GitConflictResolutionAssignment."


2. Task 2: Navigate to the "GitConflictResolutionAssignment" directory in your terminal or command prompt.


3. Task 3: Initialize a new Git repository in this directory.


4. Task 4: Create a new text file named "README.md" in the repository.


Part 2: Creating Conflict 


1. Task 1: Open the "README.md" file using a text editor or a command-line text editor like Vim or Nano.


2. Task 2: Add some content to the "README.md" file. For example:


   

   # Git Conflict Resolution Assignment


   This is the main README file.

   


3. Task 3: Save the changes to the "README.md" file and exit the text editor.


4. Task 4: Create a new branch named "feature/branch-A."   

   git branch feature/branch-A

   


5. Task 5: Switch to the new branch.   

   git checkout feature/branch-A

   


6. Task 6: Open the "README.md" file again and add some content specific to branch A.

  

   nano README.md  


   For example:

   

   # Git Conflict Resolution Assignment - Feature A


   This is a feature A branch-specific change.

   


7. Task 7: Save the changes and exit the text editor.


Part 3: Creating Another Conflict


1. Task 1: Switch back to the main branch.   

   git checkout main

   


2. Task 2: Open the "README.md" file and make conflicting changes in the same region where "feature/branch-A" made changes.   

   nano README.md

   

   For example:

   

   # Git Conflict Resolution Assignment


   This is the main README file with a conflicting change.

   


3. Task 3: Save the changes and exit the text editor.


4. Task 4: Create a new branch named "feature/branch-B."   

   git branch feature/branch-B

   


5. Task 5: Switch to the new branch.   

   git checkout feature/branch-B

   


6. Task 6: Open the "README.md" file and make changes specific to branch B.   

   nano README.md

   


   For example:   

   # Git Conflict Resolution Assignment - Feature B


   This is a feature B branch-specific change.

   


7. Task 7: Save the changes and exit the text editor.


Part 4: Resolving Merge Conflicts 


1. Task 1: Attempt to merge "feature/branch-A" into the main branch.

   

   git merge feature/branch-A   


   You will encounter a merge conflict.


2. Task 2: Resolve the conflict by opening the "README.md" file, identifying the conflicting sections (usually marked with conflict markers), and manually editing the file to keep the desired changes.


3. Task 3: Save the changes in the "README.md" file.


4. Task 4: Add the resolved file to the staging area.

   

   git add README.md

   


5. Task 5: Commit the resolved changes with a meaningful commit message.

   

   git commit -m "Resolved merge conflict in README.md"

   


6. Task 6: Attempt to merge "feature/branch-B" into the main branch.

   

   git merge feature/branch-B

   


   You will encounter another merge conflict.


7. Task 7: Resolve this conflict by following the same process as before. Open the "README.md" file, edit it to keep the desired changes, save the file, add it to the staging area, and commit the resolved changes.



Solutions

Part 1: Repository Setup


1. Task 1: Create a new directory for the assignment.   

   mkdir GitConflictResolutionAssignment

   


2. Task 2: Navigate to the "GitConflictResolutionAssignment" directory.   

   cd GitConflictResolutionAssignment

   


3. Task 3: Initialize a new Git repository.   

   git init

   


4. Task 4: Create a new text file named "README.md."   

   touch README.md

   


Part 2: Creating Conflict


1. Task 1: Open the "README.md" file using a text editor or a command-line text editor like Vim or Nano.

   

   nano README.md  # Use your preferred text editor

   


2. Task 2: Add some content to the "README.md" file. For example:

   

   # Git Conflict Resolution Assignment


   This is the main README file.

   


3. Task 3: Save the changes to the "README.md" file and exit the text editor.


4. Task 4: Create a new branch named "feature/branch-A."   

   git branch feature/branch-A

   


5. Task 5: Switch to the new branch.   

   git checkout feature/branch-A

   


6. Task 6: Open the "README.md" file again and add some content specific to branch A.   

   nano README.md

   


7. Task 7: Save the changes and exit the text editor.


Part 3: Creating Another Conflict


1. Task 1: Switch back to the main branch.   

   git checkout main

   


2. Task 2: Open the "README.md" file and make conflicting changes in the same region where "feature/branch-A" made changes.   

   nano README.md

   


3. Task 3: Save the changes and exit the text editor.


4. Task 4: Create a new branch named "feature/branch-B."   

   git branch feature/branch-B

   


5. Task 5: Switch to the new branch.   

   git checkout feature/branch-B

   


6. Task 6: Open the "README.md" file and make changes specific to branch B.   

   nano README.md

   


7. Task 7: Save the changes and exit the text editor.


Part 4: Resolving Merge Conflicts


1. Task 1: Attempt to merge "feature/branch-A" into the main branch.   

   git merge feature/branch-A

   


   You will encounter a merge conflict.


2. Task 2: Resolve the conflict by opening the "README.md" file, identifying the conflicting sections (usually marked with conflict markers), and manually editing the file to keep the desired changes.


3. Task 3: Save the changes in the "README.md" file.


4. Task 4: Add the resolved file to the staging area.   

   git add README.md

   


5. Task 5: Commit the resolved changes with a meaningful commit message.   

   git commit -m "Resolved merge conflict in README.md"

   


6. Task 6: Attempt to merge "feature/branch-B" into the main branch.   

   git merge feature/branch-B

   

   You will encounter another merge conflict.


7. Task 7: Resolve this conflict by following the same process as before. Open the "README.md" file, edit it to keep the desired changes, save the file, add it to the staging area, and commit the resolved changes.



bottom of page