Welcome to the Catch the Vision Workshop's Python Calculator repository! 👋 This workshop is designed to help participants learn Git through practical exercises focused on building a simple command-line calculator collaboratively. 🧑🤝🧑
In this exercise, we will be managing merge conflicts. 🧐
Firstly, let's define what we mean by a merge conflict. 🤔 A merge conflict occurs when Git is unable to automatically resolve differences in code between two commits. When all the changes in the code occur on different lines or in different files, Git will successfully merge commits without your help. But if there are conflicting changes on the same lines, a "conflict" occurs because Git doesn’t know which code to keep and which to discard.
Merge conflicts typically occur when:
- Several people have changed the same lines of the same file. ✍️
- One person decided to delete a file while another person decided to modify it. 📁 ❌
- There are changes in the local branch which have not been committed yet, and those changes overlap with another branch's committed changes. 👥
Resolving merge conflicts involves three steps:
-
Identifying the conflict: Git will mark the area in your code where conflict has arisen. It does so by enclosing the conflicting changes between
<<<<<<< HEADand=======, and ends with>>>>>>> branch-name. -
Reviewing the conflict: Analyze the code and determine which parts you want to keep and which parts to discard. This step requires communication between the developers involved in the conflict. 💬
-
Resolving the conflict: Once the desired changes are chosen, manually edit the code to resolve the conflict, remove the conflict markers, and save the file. 📝
After resolving the conflict, commit the resolved file to finalize the merge. ✅
Now, let's put this into practice. 🚀
For this exercise, each of you will receive a piece of paper with the complete main.py file's code except for five missing functions. Your task is to collaboratively add these missing functions to the top of the main.py file and integrate it into the current file. But here's the twist:
- Commit Requirements: Make sure there are at least four commits in the process.
- Team Collaboration: Each team member should contribute at least one commit.
- Unique Contributions: Each function insertion commit must be contributed by a different team member.
- Code Execution: Ideally, the resulting
main.pyfile should run successfully. This, however, is optional and not a strict requirement for this exercise.
First, one of the team members needs to fork the repository. This creates a copy of the repository under their own account, allowing you to make changes without affecting the original repository.

Once the repository has been forked, the team member who forked it needs to add the rest of the team as collaborators. This can be done through the settings of the repository on GitHub.

Now, every team member can clone the forked repository to their local machines:
$ git clone <forked-repository-url>Once you have the repository on your local machine, open the main.py file and add the missing function to the top of the file. Save your changes.
After you've added the function, commit the changes with a meaningful commit message:
$ git add main.py
$ git commit -m "Added <function-name> to main.py"Now, push your changes to the remote repository:
$ git push origin mainIf Git indicates a merge conflict when you try to push your changes, you'll need to pull the latest version of the code:
$ git pull origin mainGit will likely tell you that there are conflicts that need to be resolved. Open the main.py file, find the conflict (marked with <<<<<<< HEAD, =======, and >>>>>>> branch-name), and decide which changes to keep.
Once you've resolved the conflict, remove the conflict markers, save the file, and then commit it:
$ git add main.py
$ git commit -m "Resolved merge conflict in main.py"
$ git push origin mainRepeat this process until all the missing functions are added and all merge conflicts are resolved. By the end of this exercise, you'll have a working main.py file with all the missing functions added by different team members, and more importantly, you'll have gained hands-on experience in managing merge conflicts. Happy coding! 💻 🔧 💡