Technology

Fork, Pull Request & Merge

A comprehensive step-by-step guide to forking a repository, creating a pull request, and merging changes on GitHub.

In this guide, you'll learn how to contribute to a project by forking it, making changes, and submitting a pull request to merge those changes back into the original repository.

Why Fork & PR?

Forking allows you to freely experiment with changes without affecting the original project. Pull Requests (PRs) are the bridge that lets you propose those changes for review and eventual merging into the main project.


Phase 1: Forking the Repository

Forking creates a personal copy of someone else's project in your own GitHub account.

Navigate to the original repository on GitHub and click the Fork button located in the top-right corner of the page.

Step 1 screenshot

Select your own GitHub account or an organization where you want the fork to be created.

Step 2 screenshot

If you are part of multiple organizations, ensure you select the correct one (e.g., tech-dti).

Step 3 screenshot

You can keep the original name or give it a new one. Type a name if you wish to change it.

Step 4 screenshot

Click the Create fork button. GitHub will now copy the repository to your account.

Step 5 screenshot


Phase 2: Making Changes

Once you have your own fork, you can make changes directly through the GitHub Web UI (or locally on your machine).

In your forked repository, click on the file you want to edit (e.g., README.md).

Step 6 screenshot

Click on the Edit this file (pencil icon) to start making changes.

Step 7 screenshot

Type your changes into the editor. For example, add a new label or update documentation text.

Step 8 screenshot

Click on Commit changes... at the top right to start the save process.

Step 9 screenshot

Provide a brief commit message describing your changes and click Commit changes.

Step 10 screenshot

Alternative: Making Changes Locally

If you prefer working on your own machine, you can clone your forked repository and make changes locally.

Copy the SSH or HTTPS URL of your forked repository and run the following command in your terminal:

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

Go into the project folder and open the file you want to change (e.g., README.md) in your favorite editor.

cd repository-name
# Open README.md and make your changes

Once you've made your changes, stage them and create a commit.

git add .
git commit -m "commit message"

Push your local changes back to your forked repository on GitHub.

git push origin main

Next Step

After pushing your changes locally, you can proceed to Phase 3 to create a Pull Request on GitHub.


Phase 3: Creating a Pull Request

After committing your changes to your fork, it's time to propose them to the original project.

Click on the Code tab to go back to the main view of your forked repository.

Step 11 screenshot

Click the Contribute button to see options for syncing or contributing.

Step 12 screenshot

Click on Open pull request. This will take you to the original repository's PR creation page.

Step 13 screenshot

Type a meaningful title and description for your pull request (e.g., "updated readme file").

Step 14 screenshot

Click on Create pull request. The maintainers of the original repository will now see your proposal.

Step 15 screenshot


Phase 4: Merging the Pull Request

Once the pull request is approved, it can be merged into the target branch.

As a maintainer (or if you have permissions), click the Merge pull request button.

Step 16 screenshot

You can add an extended description or notes for the merge if necessary.

Step 17 screenshot

Click Confirm merge. GitHub will now integrate the changes from your pull request into the project.

Step 18 screenshot

Success!

Your changes are now part of the main project. Don't forget to sync your fork with the upstream repository periodically to stay up to date!

On this page