How to make your first pull request on GitHub
Thanoshan MV
What is forking?
When we love someone’s repository and would like to have it in our GitHub account, we fork it so that we can work with it separately.
When we fork a repository, we get an instance of that entire repository with its whole history. After forking, we can do whatever we want to do without affecting the original version.
What is a pull request?
Pull requests are the way we contribute to group projects or open source projects.
For instance, a user Harry forks a repository of ThanoshanMV and makes changes to that repository. Now Harry can make a pull request to ThanoshanMV, but it’s up to ThanoshanMV to accept or decline it. It’s like saying, “ThanoshanMV, would you please pull my changes?”
What it means to contribute
Not only can we contribute to an open source project with code, but we can also contribute in many other ways. Some of these ways are described below.
As 99xtechnology IT firm’s hacktitude starting guide says, we can contribute to an open source project in the following ways:
- Designing: You can construct the layouts of a project to improve its usability, improve the project’s navigation and menu based on user research programs, create art for logos or t-shirts, and provide style guides for the project.
- Writing: You can write and improve the project’s documentation or translate the documentation, start a newsletter for the project or write tutorials for the project and curate highlights from the mailing list, or curate a folder of examples showing how the projects are used.
- Organizing: You can link duplicate issues, suggest new issue labels, suggest to close old open issues and ask questions on recently opened issues to move the discussion forward.
- Help others: Answer questions on open issues, review code on other people’s submissions and offer to mentor another contributor.
- Coding: Help solve any open issues, ask if you can provide any new features and improve tooling and testing.
Let’s make our first pull request!
If you’re not very familiar with Git & GitHub, please go review The beginner’s guide to Git & GitHub.
1. Fork the repository
Fork the repository by clicking the fork button on the top of the page. This will create an instance of that entire repository in your account.
2. Clone the repository
Once the repository is in your account, clone it to your machine to work with it locally.
To clone, click on the clone button and copy the link.
Open the terminal and run the following command. It will clone the repository locally.
$ git clone [HTTPS ADDRESS]
Now we have set up a copy of the master branch from the main online project repository.
We need to go to that cloned directory by running this command:
$ cd [NAME OF REPOSITORY]
3. Create a branch
It’s good practice to create a new branch when working with repositories, whether it’s a small project or contributing to a group’s work.
Branch name should be short and it should reflect the work we’re doing.
Now create a branch using the git checkout command:
$ git checkout -b [Branch Name]
4. Make changes and commit them
Make essential changes to the project and save it.
Then execute git status , and you’ll see the changes.
Add those changes to the branch you just created using the git add command:
$ git add .
Now commit those changes using the git commit command:
$ git commit -m "Adding an article to week 02 of articles of the week"
5. Push changes to GitHub
In order to push the changes to GitHub, we need to identify the remote’s name.
$ git remote
For this repository the remote’s name is “origin”.
After identifying the remote’s name we can safely push those changes to GitHub.
git push origin [Branch Name]
6. Create pull request
Go to your repository on GitHub and you’ll see a button “Compare & pull request” and click it.
Please provide necessary details on what you’ve done (You can reference issues using “#”). Now submit the pull request.
Congratulations! You’ve made your first pull request.
If your pull request is accepted you’ll receive an email.
7. Sync your forked master branch
Before submitting any pull requests to the original repository you have to sync your repository to the original one.
Even if you are not going to submit a pull request to the original repository, it’s better to sync with the original repository as some additional features and bug fixes may have been done since you forked the original repository.
Follow these steps to update/sync those changes to your master branch:
- First, check which branch you are in.
$ git branch
It’ll list all branches and indicates the current or active branch in green.
2. Switch to the master branch.
$ git checkout master
3. Add the original repository as an upstream repository.
In order to pull the changes from the original repository into your forked version, you need to add the original Git repository as an upstream repository.
$ git remote add upstream [HTTPS]
Here, [HTTPS] is the URL that you have to copy from the owner’s repository.
4. Fetch the repository.
Fetch all of the changes from the original repository. Commits to the original repository will be stored in a local branch called upstream/master.
$ git fetch upstream
Merge the changes from the upstream/master into your local master branch. This will bring your fork’s master branch into sync with the upstream repository without losing your local changes.
$ git merge upstream/master
6. Push changes to GitHub
At this point your local branch is synced to the original repository’s master branch. If you want to update the GitHub repository, you need to push your changes.
$ git push origin master
NOTE: After syncing your forked master branch you can remove that remote if you want to. But you’ll need to update/sync your repository in future too, so it’s best practice to keep it.
$ git remote rm [Remote Name]
8. Delete the unnecessary branch
Branches are created for a special purpose. Once that purpose is accomplished, those branches aren’t necessary, so you can delete them.
$ git branch -d [Branch Name]
You can delete the version of it on GitHub, too.
git push origin --delete [Branch Name]
Conclusion
GitHub is a powerful tool to control version history. Everyone can contribute to open source projects by making pull requests. Contributions aren’t always code – there are other ways to contribute, too.
Finally, I have to tell you that you shouldn’t worry if your pull requests are rejected. Maintainers spend a lot time improving their projects, and they know a lot more about their projects than we do. So don’t worry if your request isn’t merged.
Stay strong, stay positive, and never give up.
― Roy T. Bennett, The Light in the Heart
This article was originally posted on Medium.
You can contact and connect with me on Twitter.
Keep contributing to the open source world!
Deleting and restoring branches in a pull request
If you have write access in a repository, you can delete branches that are associated with closed or merged pull requests. You cannot delete branches that are associated with open pull requests.
In this article
Deleting a branch used for a pull request
You can delete a branch that is associated with a pull request if the pull request has been merged or closed and there are no other open pull requests referencing the branch. For information on closing branches that are not associated with pull requests, see «Creating and deleting branches within your repository.»
- On GitHub.com, navigate to the main page of the repository.
- Under your repository name, click
Pull requests.
Restoring a deleted branch
You can restore the head branch of a closed pull request.
- On GitHub.com, navigate to the main page of the repository.
- Under your repository name, click
Pull requests.
Further reading
- «Creating and deleting branches within your repository»
- «Managing the automatic deletion of branches»
How to cancel a pull request on github?
This way the pull request gets closed (and ignored), without merging it.
15.1k 11 11 gold badges 128 128 silver badges 208 208 bronze badges
answered Apr 13, 2012 at 14:28
lifeisstillgood lifeisstillgood
3,311 2 2 gold badges 22 22 silver badges 22 22 bronze badges
It is very far down on the page. Just scroll aaaall the way down.
Apr 6, 2013 at 21:31
Tip: The close button is on the pull request on the target repo. You won’t find it on the page for the pull request in the source repo.
Sep 16, 2014 at 16:07
Is there a way to delete a PR not just close? Thanks.
Oct 1, 2015 at 11:06
small correction needed in github help page , click on original repo for which you’ve submitted pull request. Click on the name of PR and scroll to be bottom.
Jul 22, 2016 at 10:23
The question was how to «DELETE» the pull request, not how to close it,
Mar 7, 2021 at 0:15
In the spirit of a DVCS (as in «Distributed»), you don’t cancel something you have published:
Pull requests are essentially patches you have send (normally by email, here by GitHub webapp), and you wouldn’t cancel an email either 😉
But since the GitHub Pull Request system also includes a discussion section, that would be there that you could voice your concern to the recipient of those changes, asking him/her to disregards 29 of your 30 commits.
- a/ you have a preview section when making a pull request, allowing you to see the number of commits about to be included in it, and to review their diff.
- b/ it is preferable to rebase the work you want to publish as pull request on top of the remote branch which will receive said work. Then you can make a pull request which could be safely applied in a fast forward manner by the recipient.
That being said, since January 2011 («Refreshed Pull Request Discussions»), and mentioned in the answer above, you can close a pull request in the comments.
Look for that «Comment and Close» button at the bottom of the discussion page:
Закрытие запроса на вытягивание
Вы можете закрыть запрос на вытягивание, не объединяя его в вышестоящей ветви. Это удобно, если предложенные в ветви изменения больше не нужны или если в другой ветви было предложено другое решение.
Совет. Если вы открыли запрос на вытягивание с неправильной базовой ветвью, можно не закрывать его и открывать заново, а просто изменить базовую ветвь. Дополнительные сведения см. в разделе Изменение базовой ветви запроса на вытягивание.
- В поле имени репозитория щелкните
Запросы на вытягивание.