Skip to content
Snippets Groups Projects
README.md 1.63 KiB
Newer Older
vinayavn's avatar
vinayavn committed

**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


vinayavn's avatar
vinayavn committed
Step 2: Use Terminal to see which branch you’re currently on.
vinayavn's avatar
vinayavn committed


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


vinayavn's avatar
vinayavn committed
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.
vinayavn's avatar
vinayavn committed


vinayavn's avatar
vinayavn committed
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.
vinayavn's avatar
vinayavn committed


vinayavn's avatar
vinayavn committed
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.
vinayavn's avatar
vinayavn committed


vinayavn's avatar
vinayavn committed
Step 7: Push the completed merge to the remote repository so that main reflects both feature branches.
vinayavn's avatar
vinayavn committed


vinayavn's avatar
vinayavn committed
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

vinayavn's avatar
vinayavn committed
```cpp
vinayavn's avatar
vinayavn committed
// 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;
}
vinayavn's avatar
vinayavn committed



vinayavn's avatar
vinayavn committed