πŸ‡―πŸ‡΅ ζ—₯本θͺž | πŸ‡ΊπŸ‡Έ English | πŸ‡ͺπŸ‡Έ EspaΓ±ol | πŸ‡΅πŸ‡Ή PortuguΓͺs | πŸ‡ΉπŸ‡­ ΰΉ„ΰΈ—ΰΈ’ | πŸ‡¨πŸ‡³ δΈ­ζ–‡

Understanding Fork and Pull Request on GitHub (Intro to Collaborative Development)

In the previous articles, you've mastered the basic flow of managing your own projects on GitHub. However, the true power of GitHub is unleashed not when you use it alone, but when you participate in other people's projects and develop collaboratively.

This time, we'll carefully explain the concept and specific steps of "Fork" and "Pull Request," the most important and fundamental workflow for contributing to external projects (like open-source projects) where you don't have write access. Understanding this flow is the first step toward collaborating with developers around the world.


Why is Forking Necessary? The Reason You Can't Push Directly

Naturally, you cannot directly push (upload) code to someone else's GitHub repository. If anyone could write freely, projects would become a mess, right? This is the same as not being able to enter someone else's house without a key and redecorate as you please.

So, how can you contribute to someone else's project? The answer is "Fork."

A fork is a feature that copies someone else's entire repository to your own GitHub account, creating a dedicated remote repository for yourself. Think of it as making a "personal copy" to take home and work on freely. You have full write permissions for your own forked repository.

And the mechanism for proposing the changes you've made in your own repository to the original project is the "Pull Request."


The Big Picture of Fork & Pull Request

Before we start typing commands, let's get an overview of the entire flow. The typical workflow for contributing to an open-source project consists of the following six steps.

  1. Fork: Copy the original project to your own GitHub account.
  2. Clone: Copy the "personal" repository created by the fork to your PC.
  3. Branch: Create a new branch for the modification work.
  4. Modify & Commit: Modify the code on your PC and commit the changes.
  5. Push: Push the committed content to "your own" GitHub repository.
  6. Pull Request: Send a request from your repository to the original project, asking them to incorporate your changes.

A diagram of this flow would look like this:

[Diagram: A flow showing 1. Original Repository β†’(Fork)β†’ 2. Your GitHub Repository β†’(Clone)β†’ 3. Your PC β†’(Push)β†’ 4. Your GitHub Repository β†’(Pull Request)β†’ 5. Original Repository]


In Practice! Steps to Contribute to an Open-Source Project

Now, let's go through the specific steps. For practice, we'll proceed with a scenario of proposing a simple typo fix.

Step 1: Fork the Repository You Want to Contribute To

First, open the GitHub page of the project you want to contribute to. Click the "Fork" button displayed in the upper right corner of the page.

[Image: Pointing to the "Fork" button on a GitHub project page.]

A "Create a new fork" screen will appear. Confirm the repository name, etc., and press the "Create fork" button. After a short wait, a complete copy of that repository will be created in your GitHub account.

[Image: The repository screen on your own account after forking. The URL shows your username.]

Step 2: `clone` the Forked Repository

Next, `clone` the repository "on your account" that you just created by forking to your local PC. Be careful to copy the URL of the repository you forked, not the original repository.

git clone git@github.com:your-username/forked-repository-name.git

Step 3: Create a Working Branch

Navigate into the cloned folder and create a new branch for the modifications you are about to make. It's good practice to work in a dedicated workspace without directly "dirtying" the original `main` branch. Using `checkout -b` allows you to create and switch to the new branch at the same time.

cd forked-repository-name

git checkout -b fix-typo-in-readme

Step 4: Modify the Code, then `commit` & `push`

On your local PC, open a file like `README.md`, make some changes like fixing a typo, and save it. Once you're done with the changes, record them with `add` and `commit` as you've learned.

git add .

git commit -m "Fix a typo in README.md"

Finally, push this commit to your own remote repository (the forked one). Don't forget to specify the branch name you created.

git push origin fix-typo-in-readme

Step 5: Create a Pull Request

Now for the climax. Go back to the page of your forked repository in your browser and refresh it. You should see a yellow notification saying "'fix-typo-in-readme' had recent pushes" and a green button labeled "Compare & pull request." Let's click this button.

[Image: The "Compare & pull request" button displayed on the forked repository.]

You will be taken to the "Open a pull request" page. Here, you will create a request letter to have your changes incorporated into the original project.

[Image: The Pull Request creation screen, with the title and description fields highlighted.]

Review the content and press the "Create pull request" button. Your proposal will then be sent to the maintainer of the original repository.

Step 6: Wait for Review and Merge

When a Pull Request is created, the maintainer of the original repository receives a notification. The maintainer will review your code and may leave comments or request additional changes. After some back and forth, if there are no issues with your changes, the maintainer will merge your Pull Request.

[Image: Your Pull Request showing as "Merged" with a purple icon.]

The moment it's merged, your fix officially becomes part of the project. Congratulations! This is how you contribute to open source.