Github Pull Request and Conflict Resolution

Github Pull Request and Conflict Resolution

2023, Sep 13    

After completing the settings of ‘allauth’, we have finally reached the stage of ‘merge’.
Many errors were already caught locally, and there were not many features implemented in the existing ‘main’, so it was not as difficult as expected.
However, when each team member ‘pulled’, there were various problems, but they were resolved by deleting and starting over.

However, there was one concern.

The tutor was reviewing our team’s project and had a negative view of the use of ‘allauth’.

He said that we need to know how to solve problems within basic ‘Django’ so that we can customize it later while using the library. And for this project, he would like to proceed only with the basic use of ‘Django’.

I used ‘allauth’ just because I wanted to implement more functions, but now it’s hard to change it again.
After listening to the tutor, I feel bad because it seems like he only focused on flashiness without practicing basic Django.

For now, I’m trying to implement email authentication and password retrieval, so I’ll definitely have to finish it tomorrow.

Below is what I learned today while doing a pull request and merge on GitHub.

Creating a pull request (PR) on GitHub is a fundamental step when contributing to open-source projects or collaborating with others on a codebase. Here’s a step-by-step guide on how to create a pull request:

  1. Fork the Repository:
    • Go to the GitHub repository you want to contribute to.
    • Click the “Fork” button in the upper-right corner of the repository’s page. This creates a copy of the repository in your GitHub account.
  2. Clone Your Fork:
    • Go to your forked repository on GitHub.
    • Click the “Code” button and copy the repository’s URL.
    • Open your local terminal or command prompt.
    • Navigate to the directory where you want to clone the repository.
    • Run the following command, replacing <repository-url> with the URL you copied:
      git clone <repository-url>
      
  3. Create a New Branch:
    • Change to the newly cloned repository’s directory:
      cd <repository-name>
      
    • Create a new branch for your changes. It’s a good practice to name the branch something descriptive:
      git checkout -b <branch-name>
      
  4. Make and Commit Changes:
    • Make the desired changes to the code using your preferred text editor or IDE.
    • After making changes, stage the files you want to include in the commit:
      git add .
      
    • Commit the changes with a meaningful commit message:
      git commit -m "Your commit message here"
      
  5. Push Your Changes:
    • Push your branch to your forked repository on GitHub:
      git push origin <branch-name>
      
  6. Create a Pull Request:
    • Go to your forked repository on GitHub.
    • You should see a notice at the top of the page indicating that you’ve pushed a new branch. Click the “Compare & pull request” button.
  7. Compare Changes:
    • On the pull request creation page, compare the changes between your branch and the original repository’s branch you want to merge your changes into.
  8. Open the Pull Request:
    • Provide a title and description for your pull request, explaining what your changes accomplish and any relevant details.
    • Review the changes and ensure everything looks correct.
    • Click the “Create pull request” button.
  9. Discuss and Review:
    • Wait for the repository maintainers or collaborators to review your pull request.
    • Address any comments or feedback they provide by making additional commits to your branch.
  10. Merge the Pull Request:
    • Once your pull request is approved and passes any required tests or checks, the repository maintainers can merge your changes into the main branch.

Congratulations! You’ve successfully created and contributed to a pull request on GitHub. Remember to keep your branch updated with the latest changes from the original repository by syncing or rebasing as needed.

Resolving conflicts when merging a pull request on GitHub is a common part of the collaborative coding process, especially when multiple contributors make changes to the same code in parallel. Conflicts occur when Git cannot automatically merge the changes due to conflicting modifications in the same part of a file. Here’s how to resolve conflicts using GitHub’s web interface:

  1. Create a Pull Request:
    • Ensure that you have a pull request (PR) that you want to merge, but it has conflicts with the target branch.
  2. Identify Conflicts:
    • GitHub will automatically detect conflicts in your PR and display a message like “This branch has conflicts that must be resolved.” You’ll also see a “Resolve conflicts” button. Click this button to start the conflict resolution process.
  3. Review Conflicts:
    • GitHub will present you with a side-by-side comparison of the conflicting changes in the files.
    • Conflicting sections will be marked with <<<<<<<, =======, and >>>>>>> to indicate the conflict.
    • Your changes will be on the left side, and the target branch’s changes will be on the right side.
  4. Resolve Conflicts:
    • Manually edit the conflicting parts of the code in the editor.
    • Remove the conflict markers (<<<<<<<, =======, and >>>>>>>) and make the necessary changes to resolve the conflict.
    • You can choose to keep one side’s changes, combine them, or make entirely new changes based on your requirements.
    • Be sure to review the entire file to ensure that there are no other unnoticed conflicts.
  5. Commit Changes:
    • After resolving all conflicts, scroll down to the bottom of the page.
    • You’ll find a commit message box where you can provide a description of the conflict resolution. This message is used for the merge commit.
    • GitHub will automatically create a new branch for this resolution, but you can modify the branch name if needed.
  6. Commit Merge:
    • Click the “Commit merge” button to apply the conflict resolution to your branch.
  7. Merge Pull Request:
    • After successfully committing the merge, you can now proceed to merge the pull request as usual.
    • Click the “Merge pull request” button.
  8. Confirm Merge:
    • You may need to provide a merge commit message or accept the default one.
    • Click the “Confirm merge” button to complete the merge.
  9. Delete Branch (optional):
    • After merging, you can choose to delete the branch that had the conflicts, especially if it was created solely for the purpose of the pull request.

By following these steps, you can effectively resolve conflicts and merge a pull request on GitHub. Keep in mind that communication with collaborators is crucial during this process to ensure that the resolved conflicts align with the project’s goals and coding standards.