How to create a PR (Pull Request) on GitHub?

How to create a PR (Pull Request) on GitHub?

0xBirdie's photo
0xBirdie

Published on Jun 9, 2021

3 min read

Subscribe to my newsletter and never miss my upcoming articles

When I first started to code primarily in PHP (Laravel), I never knew how to contribute to other open source repositories and I seldom found a documentation on how to create a Pull Request also short-termed PR... So, for the fellow beginners, I have made this documentation about how can we contribute to other repositories by creating a PR.


Let's start everything by creating a Fork.

You can fork a GitHub repository by just going to the GitHub repository URL, and clicking on the Fork Button some alt

Then, clone the forked repo by

git clone https://github.com/{userName}/{forkedRepo}.git

Create a new working branch

Right after cloning the repo, switch to a new branch because we dont want to mess with the main/master branch, you do this by

git checkout -b {newBranchName}

The branch name can be anything, just it shouldn't get conflicted with other branch names, such as, when you create a branch testing and the branch already exists on the main upstream, it will create conflicts.

After switching branches,

Commit the changes

after cloning and going into your project, make your changes like creating new files, editing files or deleting files, and after you are done,

to commit the changes, first, add all the edited or new files by

git add .

and then commit it with a comment by,

git commit -m "some message here"

and by this you have commited your changes, only thing left is pushing those changes some alt

Pushing the changes

After we are done commiting, we need to push it to the forked repo, we will do this by,

git push -u origin {branchName}

some alt Note: origin here refers to the remote repo, and it may be different, please check your remote repo using command,

git remote

default is origin

Creating a PR

Finally, after all things done, we have to just create a pull request to the remote upstream, we do this by going to the forked repo, and github will automatically reminds us that our repo is n commits ahead the main branch of remote upstream, some alt We will just click on the compare & pull request button to start creating a PR. it will show something like this some alt We will now add a title and a description about what we changed to created. after it, we will just click on the create pull request

And voila! PR is created

Now, we will just wait for the moderators to review your changes and merge the Pull Request.

I hope this was compact and an easy to understand documentation on how to create a Pull Request on GitHub.

Bye! 👋

 
Share this