Forking and Submitting Pull Requests

Tutorial 3 of 5

1. Introduction

In this tutorial, you are going to learn how to fork a repository and submit pull requests on GitHub.

Forking a repository allows you to freely experiment with changes without affecting the original project. A Pull Request (PR) is the heart of collaboration on GitHub. When you open a pull request, you're proposing your changes and requesting that someone review and pull in your contribution and merge them into their branch.

After completing this tutorial, you'll be able to:

  • Fork a repository on GitHub.
  • Make changes to the forked repository.
  • Submit a pull request.

Prerequisites: Before beginning this tutorial, you should have a basic understanding of Git and GitHub. You should also have Git installed on your local machine and a GitHub account.

2. Step-by-Step Guide

Forking a Repository

  1. Go to the GitHub page of the repository you want to fork.
  2. Click on the 'Fork' button at the top right corner of the page.
  3. This will create a copy of the repository in your GitHub account.

Cloning the Repository

  1. Go to your GitHub account, open the forked repository, click on the 'Code' button, and then click the 'copy to clipboard' icon to get the repo URL.
  2. Open a terminal on your computer.
  3. Change the current working directory to the location where you want the cloned directory.
  4. Type git clone, and then paste the URL you copied earlier. It will look like this: git clone https://github.com/YOUR-USERNAME/REPOSITORY-NAME.git
  5. Press Enter. Your local clone will be created.

Making Changes and Committing

  1. Navigate to the cloned directory on your computer.
  2. Make changes to the files as desired.
  3. Stage the changes by using git add . command.
  4. Commit the changes using git commit -m "Your commit message".

Pushing Changes and Creating Pull Request

  1. Push the changes using git push origin master.
  2. Go to your GitHub account, navigate to the forked repository and click 'New pull request'.
  3. In the 'New pull request' page, ensure that the base fork is the repository you want to merge your changes into. The head fork is your repository where the changes are made.
  4. Click 'Create pull request', add any additional comments, and then confirm.

3. Code Examples

# Clone the repository
git clone https://github.com/YOUR-USERNAME/REPOSITORY-NAME.git

# Navigate to the directory
cd REPOSITORY-NAME

# Make changes to the files

# Stage the changes
git add .

# Commit the changes
git commit -m "Your commit message"

# Push the changes
git push origin master

4. Summary

In this tutorial, we learned how to fork a repository on GitHub, make changes to the forked repository, and submit a pull request. These are important steps for contributing to open source projects.

Next, you can practice these steps by contributing to some open source projects. You can also learn more about other Git commands and GitHub features.

5. Practice Exercises

  1. Find an open-source project on GitHub, fork it, clone it to your local machine, make some changes, and submit a pull request.

  2. Create a new repository on your GitHub account, clone it to your local machine, make some changes, push the changes to GitHub, and then try to submit a pull request to the original repository.

Remember, the key to mastering Git and GitHub is consistent practice. Happy coding!