Skip to content
Snippets Groups Projects
Forked from vinayavn / merging-confllict-exercise
2 commits behind the upstream repository.
vinayavn's avatar
vinayavn authored
532be2a3
History
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 Fork the Repository: Go to the repository's web page and fork it to your account. Clone the Repository: Copy the URL of your fork, then clone it to your local machine. Navigate into the Repository: Move into the directory of the cloned repository.

Step 2: Check Your Current Branch Use Git to list the available branches and see which branch you’re currently on.

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

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

Step 5: Merge feature-2 into main (Expect Conflict) Switch to main: Make sure you’re on the main branch. 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: Resolve the Conflict Open main.cpp: In your text editor, you’ll see conflict markers indicating the conflicting sections. Manually Resolve the Conflict: Choose how to combine or select the changes. Remove the conflict markers and save the resolved file. Mark the Conflict as Resolved: Add the resolved file and commit the changes to complete the merge.

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

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