Day 9: Collaboration on GitHub – Forking Repositories, Pull Requests and Code Reviews, Managing Issues

Day 9: Collaboration on GitHub – Forking Repositories, Pull Requests and Code Reviews, Managing Issues

Brief Overview

On Day 9, we will cover:

  1. Forking Repositories: Creating your own copy of someone else's repository.

  2. Pull Requests and Code Reviews: Proposing changes and getting feedback.

  3. Managing Issues and Discussions: Tracking tasks and engaging in discussions.


Detailed Explanation

1. Forking Repositories

Forking is the process of creating a personal copy of a repository under your GitHub account. This allows you to experiment with changes without affecting the original project.

Steps to Fork a Repository:

  1. Find the Repository to Fork:

    • Navigate to the repository you want to fork on GitHub.
  2. Click the Fork Button:

    • In the upper-right corner of the repository page, click the "Fork" button.

    • GitHub will create a copy of the repository in your account.

  3. Clone Your Fork:

    • After forking, you can clone your copy to your local machine to start working on it.
    git clone https://github.com/your-username/repository-name.git
  1. Work on Your Fork:

    • Make changes to your fork as needed, commit them, and push them to your GitHub fork.
    git add .
    git commit -m "Describe your changes"
    git push origin main

Example: Suppose you find a project you like, and you want to add a new feature. You fork the repository, clone it, make your changes, and push them to your fork. If you want your changes to be included in the original project, you can create a pull request.

2. Pull Requests and Code Reviews

Pull Requests (PRs) are a way to propose changes to a repository. They let you submit your changes for review and discussion before merging them into the main project.

Steps to Create a Pull Request:

  1. Push Your Changes:

    • Make sure your changes are pushed to a branch in your forked repository.
    git push origin your-branch-name
  1. Open a Pull Request:

    • Go to the repository on GitHub where you want to propose changes.

    • Click the "Pull requests" tab.

    • Click "New pull request."

    • Select the branch you made changes in and compare it with the base branch (usually main or master).

    • Click "Create pull request."

  2. Provide Details:

    • Add a title and description explaining your changes.

    • Click "Create pull request."

Example:

# Pull Request: Add Search Functionality

## Description
This PR introduces a new search feature for filtering items in the app.

## Changes
- Added search bar component
- Implemented search functionality in the backend

## Related Issues
- Resolves #45

Code Reviews:

  • After creating a pull request, team members can review the changes, leave comments, and request modifications.

  • You can address feedback by making additional commits to your branch.

Example:

  • Review Comments:

    • "Consider refactoring this function for better readability."

    • "Can you add test cases for this new feature?"

  • Address Feedback:

    • Make changes based on the comments.

    • Push the updated code to the same branch.

    git add modified-file.js
    git commit -m "Refactor search function as per review feedback"
    git push origin your-branch-name

3. Managing Issues and Discussions

Issues:

  • Issues are used to track tasks, bugs, and feature requests in a repository.

Steps to Create an Issue:

  1. Navigate to Issues:

    • Go to the "Issues" tab in your repository on GitHub.
  2. Create a New Issue:

    • Click "New issue."

    • Provide a title and description.

    • Optionally, add labels, assign it to team members, and set milestones.

    # Issue: Fix Navigation Bug

    ## Description
    The navigation bar disappears when resizing the browser window.

    ## Steps to Reproduce
    1. Open the app.
    2. Resize the window.

    ## Expected Result
    The navigation bar should remain visible.
  1. Submit the Issue:

    • Click "Submit new issue."

Discussions:

  • Discussions allow team members to have conversations about various topics related to the repository.

Steps to Use Discussions:

  1. Navigate to Discussions:

    • Go to the "Discussions" tab in your repository.
  2. Create a New Discussion:

    • Click "New discussion."

    • Choose a discussion category (e.g., Q&A, Ideas, or General).

    • Provide a title and description.

    • Click "Start discussion."

Example Discussion:

# Discussion: Feature Request for Dark Mode

## Summary
It would be great to add a dark mode feature to the application for better usability in low-light environments.

## Benefits
- Reduces eye strain
- Saves battery life on OLED screens

Example Workflow:

  1. Fork a Repository:

     git clone https://github.com/your-username/repository-name.git
    
  2. Create a New Branch and Make Changes:

     git checkout -b add-dark-mode
     # Make changes to add dark mode
     git add .
     git commit -m "Add dark mode feature"
     git push origin add-dark-mode
    
  3. Create a Pull Request:

    • On GitHub, go to your forked repository.

    • Click "Pull requests" and then "New pull request."

    • Compare add-dark-mode with main and create a pull request.

  4. Review and Merge:

    • Review feedback from collaborators.

    • Make necessary changes and push them to the branch.

    • Once approved, merge the pull request.

  5. Create and Manage Issues:

    • Report bugs or request features using the Issues tab.

    • Discuss and track progress using discussions.


By the end of Day 9, we understand how to collaborate on GitHub effectively, including forking repositories, creating and reviewing pull requests, and managing issues . This knowledge will help you to work more efficiently with others and contribute to open-source projects.