1. Collaboration Workflow: Forking, Cloning, and Pull Requests

To contribute to a repository that you do not own, follow these steps:
-
Fork the Repository:
In the GitHub repository you want to contribute to, click the “Fork” button in the top right corner. This creates a copy under your GitHub account. - Clone the Forked Repository:
git clone https://github.com/your-username/repository-name.git cd repository-name - Create a New Branch and Make Changes:
git checkout -b my-feature-branch echo "New feature added" > feature.txt git add feature.txt git commit -m "Added a new feature" - Push the Changes to Your Fork:
git push origin my-feature-branch - Create a Pull Request:
In the original repository on GitHub, click “Compare & pull request”. Then, add a description and submit the pull request for review. If approved, the repository owner reviews your PR and merges it into the main project.
2. Handling Merge Conflicts

-
Simulating a Merge Conflict
A merge conflict happens when Git cannot automatically reconcile changes from two branches modifying the same part of a file differently. This commonly occurs in real-world projects when two team members working on separate feature branches make changes to the same file and attempt to merge their branches into the main branch.Let’s simulate this scenario locally by committing changes to the same file in different branches:
git checkout -b conflicting-branch echo "Change from conflicting branch" >> todo.txt git commit -am "Conflicting change" git checkout main echo "Change from main branch" >> todo.txt git commit -am "Main branch change" git merge conflicting-branchAt this point, Git detects a conflict and marks the conflicting sections in
todo.txt. -
Identifying & Resolving the Conflict
Opentodo.txt, and you’ll see something like this:<<<<<<< HEAD Change from main branch ======= Change from conflicting branch >>>>>>> conflicting-branchTry
git statusto understand more about the status at this unmerged state.Manually edit the file to resolve the conflict:
- Keep one change
- Combine both changes
- Modify the content to create a better version
Then, stage and commit the resolved file:
git add todo.txt git commit -m "Resolved merge conflict between main and conflicting-branch" -
Aborting the Merge
If you decide to cancel the merge entirely, use:git merge --abortThis restores the repository to its previous state before the merge started.
Conclusion
In this guide, you’ve learned how to collaborate using Git and handle merge conflicts. These are essential skills for working in real-world development teams. By mastering these concepts, you’ll be able to contribute effectively to any project.
Want to revisit the basics? Check out Learn Git: Mastering the Basics.