How to send a pull request on GitHub
Do you want to contribute to a GitHub repository that is not yours? Maybe an open-source project? Then sending a pull request is the answer.
Fork a repository
Go to a repository page on GitHub, find and click the Fork button. Select your user and give the forked repository a name.
Clone the forked repository
In your command line software by choice (mine are Terminal and Visual Studio Code), clone the forked repository. In my example, I have forked the processwire repository by ProcessWire (github.com), and named it processwire.
git clone https://github.com/myusername/processwire-forked.git
Create a new branch
Navigate to the repository's folder on your computer, then create a new branch where you will to the changes. Also switch to that branch. I will call the new branch issue-1. Do it at the same time with this command:
git checkout -b issue-1
Edit, commit and push
Do the changes to your code. Add the changes to stage, commit them and push the commits to a new branch in your forked repository on GitHub. In my case, I edited some typos in README.md.
git add README.md
git commit -m "fixed typos"
git push origin issue-1
Send pull request
Go to the page of your forked repository on GitHub. You will now see an alert on top of the page about your recent pushes. And also a button for Compare & pull request. Click it.
Depending on what the rules are for the repository you are contributing to, write some meaningful text about your pull request. At least what it contains. Some repositories have guidelines you should follow.
Above the title and comment input fields are some dropdown menus to select where you want to send the pull request. In my case, it was correct by default, which was the main repository at processwire/processwire.
Wait
It could take minutes, hours or days before your pull request is approved or declined. Depending on who is in charge of the repository.
Delete branch
Let's say it gets an approval. A new button appears, to delete the branch issue-1 from GitHub. I do not need this branch, so I will delete it by clicking Delete branch from the pull request page. You can also delete branches from elsewhere in GitHub or the command line.
Also, I will delete the branch locally. First I will switch to the main branch. The delete.
git checkout main
git branch -D issue-1
Fetch the latest version of the repository
After the pull request has been approved to the processwire repository, I want to fetch it (and other possible changes/updates) to my computer.
git remote add upstream https://github.com/processwire/processwire.git
This command will add a remote connection called upstream. Meaning that I can now pull the most recent version from processwire/processwire and push my own changes to myusername/processwire-forked.
Let's fetch the most recent version, and reset the local repository. And the push these changes to my forked repository on GitHub.
git fetch upstream
git reset --hard upstream/main
git push
When I navigate to the page for my forked repository on GitHub, there will be a message above the file list saying This branch is up to date with processwire/processwire:main.
Repeat
To make another pull request, do it all again:
Create a new branch locally
Edit, commit and push changes to your forked repository on GitHub
Send a pull request and wait
Delete the branch from GitHub and locally
Fetch the latest version of the (original) repository
Push the latest version to your forked repository on GitHub
Summary
Hopefully, this guide will get you there, or be a reminder of the necessary steps. If you need a more visual or thorough walkthrough, check out Web Dev Cody's video below: