How to create pull request

In this blog, we are going to understand how to contribute to other projects and create pull request for the same. Throughout the process we will know how to create branch, clone the project, push the latest changes and more.

In this post we will look how to create a pull request to an existing project to introduce some changes required in the project.
So in order to create a pull request one must have to go through the process listed below:

  • Fork the existing project
  • Create a separate branch
  • Introduce the required changes
  • Finally, create a pull Request

So let's get started.

Fork the project

In order to add changes to the project one must the local copy of the project. In most cases when creating pull request for the project which you do not already own, one must first fork the project.

Forking a project means to create a independent copy of the project, just like creating a new repository which belongs to you under your account. This basically avoids to directly pushing changes to the original project, which may also require you the permission to directly push to the repository which you do not own or maintain.

To fork the project:

  • Navigate to the original project on Github
  • Click on the fork button on top right of the repository

This will create the repository with same name under your Github account.
Additionally, clone the repository under your account to your system using the following command, but before that click on the clone option in repository, and copy the URL.
Execute the following command in terminal.

git clone PROJECT_URL.git

Create separate branch

​So, in-order to introduce changes, one must create a separate branch and then start editing the project or files under it.
​To create a separate branch, open the terminal in the cloned project repository/folder and execute the following command replacing the name of branch as per your choice.​

git checkout -b YOUR_BRANCH_NAME

​Introducing required changes

​Now it's time to implement required changes in the project. Just go ahead and do whatever changes you want.
​Once the changes are done, one needs to commit those changes to the branch using the following command below.​

git commit -a -m "Message for your commit (description of changes)"

​After committing the changes push these changes to the branch using the command below.

git push origin YOUR_BRANCH_NAME

​Finally, creating a Pull request

So, once you are done with the changes and committing and pushing them to the repository, now its time to create a pull request to the original repository of project, so that owner or maintainers of the project can review your changes and take decision whether or not to merge your changes with the project.

So to create pull request do the following.

  • Navigate to repository under your account
  • Switch to the branch under which you pushed the changes from the branches option
  • Click on the pull request button visible to you or click on contribute.
  • Write a nice message for the pull request describing the changes
  • Finally, click on create pull request

Once owner/maintainer of the original repository agrees to merge the changes introduced, your pull request will get merged with the project. And that's a great thing, Congratulations! you made a contribution to the project.

Thanks for being with me till here! I hope now you feel ready to contribute to the projects out there. To read more content like this checkout my latest blog here.

Akash Srivastava
Software Engineer @ Seawoods Ventures Inc.
© 2019-2024 dev-akash.in