Skip to content
Snippets Groups Projects
Forked from vinayavn / merging-confllict-exercise
4 commits ahead of the upstream repository.
Name Last commit Last update
README.md
main.cpp

Git Branching and Merging Exercise

This exercise will help you practice working with Git branches, merging, and handling conflicts. The repository contains three branches (main, feature-1, and feature-2), each with a main.cpp file showing which branch it’s from. Follow these steps to complete the exercise.

Steps

Step 1: Fork and Clone the Repository

Step 2: Use Terminal to see which branch you’re currently on.

Step 3: Switch to feature-1,feature-2. You should find main.cpp with a message specific to this branch.

Step 4: Switch back to main: Change to the main branch. Merge the feature-1 branch into main. If the merge completes without conflict, push your updates to your remote repository.

Step 5: Attempt to Merge feature-2: When you try to merge feature-2, a conflict will occur in main.cpp because both branches modified the same lines.

Step 6: Open main.cpp: In your text editor (VS Code), you’ll see conflict markers indicating the conflicting sections. Manually Resolve the Conflict: Choose to combine changes . Add the resolved file and commit the changes to complete the merge.

Step 7: Push the completed merge to the remote repository so that main reflects both feature branches.

Step 8: Check the history to confirm that both feature-1 and feature-2 were successfully merged without any unresolved conflicts.

Your final main.cpp should look like this before the final commit

// main.cpp
#include <iostream>

int main() {
<<<<<<< HEAD
    std::cout << "This is Feature 1's version" << std::endl;
=======
    std::cout << "This is Feature 2's version" << std::endl;
>>>>>>> feature-2
    return 0;
}