Git & GitHub / GitHub Basics

Forking and Submitting Pull Requests

This tutorial will teach you how to fork a repository and submit pull requests. These are important skills for collaborating on GitHub projects and contributing to open source.

Tutorial 3 of 5 5 resources in this section

Section overview

5 resources

Introduces the basics of GitHub, including repositories, pull requests, and forking.

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!

Need Help Implementing This?

We build custom systems, plugins, and scalable infrastructure.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

HTML

Learn the fundamental building blocks of the web using HTML.

Explore

CSS

Master CSS to style and format web pages effectively.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

Unit Converter

Convert between different measurement units.

Use tool

Favicon Generator

Create favicons from images.

Use tool

MD5/SHA Hash Generator

Generate MD5, SHA-1, SHA-256, or SHA-512 hashes.

Use tool

Time Zone Converter

Convert time between different time zones.

Use tool

Scientific Calculator

Perform advanced math operations.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI in Public Safety: Predictive Policing and Crime Prevention

In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…

Read article

AI in Mental Health: Assisting with Therapy and Diagnostics

In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…

Read article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help