🔗 How to make a pull request on GitHub - a quick tutorial
So you made changes to a project — a bugfix or maybe a new feature — and you want to send it for inclusion in the official (“upstream”) sources. Perhaps you sent an email or opened an issue in the bugtracker, and the project maintainers asked you to send a Pull Request (PR) on GitHub. But how to do this? Here’s a quick how-to guide!
Step 0 - Have a GitHub account
Before anything, you need to have a GitHub account! If you don’t have one already, go to github.com and sign up. Just follow the instructions, it’s easy and free.
Step 1 - “Fork the repository”
“Forking a repository” on GitHub means creating your own Git repository, which is a copy of the original.
Let’s visit a repository and fork it. Start by visiting https://github.com/hishamhm/pull-request-tutorial
In the upper-right there’s a button named “Fork”. It also shows a number: how many times this repository was forked by other people).
Press it, and it will create your own copy of the pull-request-tutorial
repository, at https://github.com/YOUR_USERNAME/pull-request-tutorial
(the real URL will, of course, contain your own username).
Step 2 - Download your fork and create a branch
Now, it’s time for you to make your changes in the source code (your bugfix or new feature). Start by downloading your repository to your computer. Go to the terminal, make sure git
is installed in your computer and type:
git clone https://github.com/YOUR_USERNAME/pull-request-tutorial.git
This will download the files and create a directory called pull-request-tutorial
that is linked to your fork (i.e. the copy of the repository under your control).
To avoid trouble later, let’s create a new “branch” in our repository so that the work on our bugfix or feature is stored separately. Pick a meaningful name that represents the changes you plan to make in your code. In our example, I’ll call it “fix-typo”:
git checkout -B fix-typo
Step 3 - Make your changes in your fork
Now enter the directory of your local fork, and edit it at will, implementing your bugfix or feature.
If you create a new file, remember to add it with git add
:
git add new_file.txt
Commit your changes, adding a description of what was added. If you’re not used to Git, the simplest way is to commit all modified files and add a description message of your changes in a single command like this:
git commit -a -m "Fix typo in README file"
(But there are lots of ways to choose which files (and even parts of files) do commit and edit the commit message. Look for the Git documentation for details.)
Once your changes are committed, “push” the changes: send them to your GitHub repository using git push
git push
(The first time you push from a branch, Git will complain that your local branch in your computer is not connected to a branch in the GitHub server. Just do what the command tells you to do:
git push --set-upstream origin fix-typo
Next time you push again to this repository, just “git push” will do fine.)
Now, when you visit https://github.com/YOUR_USERNAME/pull-request-tutorial
again, you should see your changes there.
Step 4 - Make the Pull Request
This is the simplest step! In your repository page, the next time you open the page after pushing to a new branch, there’s a big green button saying “Compare & pull request”. Press it!
This will open a page in which you’ll be able to further edit the description for your proposed changes. Write down a nice report explaining why these changes should be included in the official sources of your project, and then confirm.
The project authors will receive an email notification that you sent them a PR. Then it’s their turn to read it and comment. You will get notifications when they comment. If they suggest any changes to your bugfix or feature, go back to Step 3, edit it and push again: your Pull Request will be automatically updated. If they are happy with the changes and want to integrate your contributions to the project, the maintainers will click “Merge” and your code will become part of the original repository!
If you want to give it a try, feel free to use the repository I created for this tutorial: https://github.com/hishamhm/pull-request-tutorial
Fork it, edit it, commit and push your changes and send me a PR!
If you liked this tutorial, leave a star on its repo. :)
Follow
🐘 Mastodon ▪ RSS (English), RSS (português), RSS (todos / all)
Last 10 entries
- Why I no longer say "conservative" when I mean "cautious"
- Sorting "git branch" with most recent branches last
- Frustrating Software
- What every programmer should know about what every programmer should know
- A degradação da web em tempos de IA não é acidental
- There are two very different things called "package managers"
- Last day at Kong
- A Special Hand
- How to change the nmtui background color
- Receita de Best Pancakes