🐙
Git Developer Guide
About
  • Overview
  • Scope of this book
  • Table of Content
  • 🐢Introduction to Version Control
    • What is Version Control?
    • Overview of git and it's benefits
    • Setting up Git on Different Platforms
  • 🍼Git Fundamentals
    • Initialising a new Git repository
    • Understanding the Git Workflow
    • Committing Changes and Writing Good Commit Messages
    • Viewing and Navigating Commit History
    • Git Basics - Practice Scenarios
      • Initialising a Git Repository
      • Committing Changes
      • Exploring Commit History
      • Amending and Undoing Commits
  • 🦕Working With Git
    • What is Git Branch?
    • Creating and Switching Between Branches
    • Merging Branches and Resolving Conflicts
    • Best Practices for Branch Management
    • Git Workflows
    • Git Log
    • Git Stash
    • Working with Git - Practice Scenarios
      • Creating and Switching Between Branches
      • Merging Branches and Resolving Conflicts
      • Branching Strategies in a Team Project
      • Rolling Back to a Previous Version
      • Experimenting with Feature Branches
      • Working with Stash
  • 🤝Working with Remote Repositories
    • Cloning a Repository from Remote
    • Pushing and Pulling Changes to and from Remote Repositories
    • Collaborative Workflows - Forking, Branching, and Pull Requests
    • Resolving Conflicts in a Collaborative Environment
    • Collaborating with Git - Practice Scenarios
      • Cloning a Remote Repository
      • Pushing and Pulling Changes
      • Collaborative Workflow with Forking and Pull Requests
      • Resolving Conflicts in a Pull Request
  • 🏆Advanced Git Features
    • Aliases and Custom Configurations
    • Working with Tags and Releases
    • Rewriting Commit History with Interactive Rebase
    • Utilising Git Hooks for Automation
    • Advanced Git Features - Practice Scenarios
      • Creating Custom Git Aliases
      • Working with Tags and Releases
      • Rewriting Commit History with Interactive Rebase
      • Using Git Hooks for Automated Testing
  • 😎Git in Real-World
    • Managing a Project with Multiple Contributors
    • Integrating Git with Continuous Integration, Continuous Deployment (CI, CD)
    • Versioning Assets with Git LFS (Large File Storage)
    • Deploying a Web Application using Git
    • Git In Real World - Practice Scenarios
      • Managing a Project with Multiple Contributors
      • Integrating Git with CICD Pipelines
      • Versioning Assets with Git LFS
      • Deploying a Web Application using Git
  • Git Troubleshooting
    • Common Mistakes and Pitfalls When Using Git
    • Undoing Changes with Git - Reverting and Resetting
    • Recovering Lost Commits or Branches
    • Dealing with Repository Corruption or Other Issues
  • Git Best Practices and Tips
    • Creating efficient git workflows: writing clean code for faster reviews
    • The importance of clean code in collaborative development
    • Significance of consistent naming conventions & coding Standards
    • Good code documentation for better git workflows
    • Writing meaningful git commit messages
    • Atomic commits in git & it's benefits for software teams
    • Structuring code & managing dependencies for better git workflows
    • Git branching strategies for software teams
  • Conclusion & Next Steps
    • Recap of Key Concepts and Commands
    • Further Resources for Expanding Git Knowledge
    • Encouragement and Tips for Continued Learning and Practice
  • License Considerations
Powered by GitBook
On this page

Was this helpful?

  1. Working with Remote Repositories
  2. Collaborating with Git - Practice Scenarios

Resolving Conflicts in a Pull Request

Scenario

This is a practical step-by-step guide on how to address conflicts that arise during the review of a pull request, emphasising effective communication and collaboration.

Step 1: Understanding the Conflict

When conflicts occur in a pull request, it means that the changes made in the branch being merged conflict with the existing codebase. To start resolving conflicts, it's crucial to understand the nature of the conflict. The pull request will provide details about the conflicting files and lines of code.

Step 2: Checking out the Branch Locally

To resolve conflicts effectively, we need to work with the conflicting code locally. Begin by cloning the repository if you haven't already and navigate to the repository's directory using the command line or a Git client. Ensure that you have the latest version of the main branch by running the following commands:

git checkout main
git pull origin main

Step 3: Checking out the Pull Request Branch

Next, check out the branch associated with the pull request that has conflicts. Execute the following command, replacing <branch-name> with the actual name of the branch:

git checkout <branch-name>

Step 4: Resolving Conflicts

Now that you're on the branch with conflicts, open the conflicting file(s) in your preferred code editor. The editor will display the conflict markers, typically consisting of <<<<<<<, =======, and >>>>>>>.

The conflicting sections will be surrounded by these markers, with the original code and the proposed changes visible. Manually edit the code to resolve the conflicts based on your understanding of the changes and the intended outcome.

Here's an example of how a conflict may appear:

<<<<<<< HEAD
def calculate_sum(a, b):
    return a + b
======= 
def calculate_product(a, b):
    return a * b
>>>>>>> feature-branch

In this example, the conflict arises because the function names and operations have been changed in both branches. Decide which version should be kept or modify the code to combine the desired changes.

Step 5: Resolving the Conflict Marks

After modifying the conflicting code, remove the conflict markers (<<<<<<<, =======, and >>>>>>>) to indicate that the conflict has been resolved. Review the code to ensure that the changes accurately reflect your intentions.

Step 6: Committing the Changes

Once you have resolved the conflicts in the file(s), save them and proceed to commit the changes. Use the following command to stage the modified files:

git add <file-name>

For multiple files, you can use the following command to stage all changes:

git add .

After staging the changes, commit them with a descriptive message:

git commit -m "Resolved conflicts in <file-name>"

Step 7: Pushing the Changes

Now that you have resolved the conflicts and committed the changes locally, it's time to push them to the remote repository. Use the following command to push the changes to the branch associated with the pull request:

git push origin <branch-name>

Step 8: Updating the Pull Request

With the conflicts resolved and the changes pushed to the remote repository, go to the pull request on the hosting platform (e.g., GitHub, Bitbucket) and refresh the page. The pull request will automatically update to reflect the changes made in the branch.

Step 9: Effective Communication and Collaboration

During the conflict resolution process, it is vital to maintain effective communication and collaboration with other team members involved in the pull request. Clearly document the changes made to resolve conflicts and provide context to reviewers.

Address any concerns or questions raised by reviewers promptly to ensure a smooth resolution.

PreviousCollaborative Workflow with Forking and Pull RequestsNextAliases and Custom Configurations

Last updated 1 year ago

Was this helpful?

🤝