How to make your first pull request on GitHub

Thanoshan MV
7 min readJan 29, 2020

--

What is forking?

Forking means, when we love someone’s repository, would like to have it in our GitHub account, so that we can work with it separately with the same stuff.

When forking we get an instance of that entire repository with whole history. After forking, we can do whatever we want to do without affecting the core original version.

What is a pull request?

Pull requests are the way to 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 “Would you please, ThanoshanMV pull my changes?”.

What it means to contribute?

Not only we can contribute to an open source project by contributing with code but also we can contribute in many aspects. Some of the aspects are defined below.

As 99xtechnology IT firm’s hacktitude starting guide says, we can contribute to an open-source project in the following ways:

  1. Designing: Reconstruct the layouts of a project to improve its usability, improve project’s navigation and menu based on user research programs, creating art for logos, t-shirts and providing style guides to the project.
  2. Writing: 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.
  3. Organizing: 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.
  4. Help others: Answer questions on open issues, review code on other people’s submissions and offer to mentor another contributor.
  5. Coding: Help to 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 much 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, now 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 a good practice to create a new branch when working with repositories whether it’s a small project or contributing to a group 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 , you’ll see 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.

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 have been done since you forked the original repository.

Follow these steps to update/sync those changes to your master branch:

a. First, check in which branch are you in.

$ git branch

It’ll list all branches and indicates the current or active branch in green color.

b. Switch to the master branch.

$ git checkout master

c. Adding 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.

d. 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

e. Merge it.

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

f. 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, if you wish you can remove that remote but you’ll need to update/sync your repository in future too. So, it’s a best practice to keep it.

$ git remote rm [Remote Name]

8. Delete unnecessary branch

Branches are created for a special purpose. Once those 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 in GitHub, too.

git push origin --delete [Branch Name]

Conclusion

GitHub is a powerful tool to control software’s version. Everyone can contribute to open-source projects by pull requesting. Contributions aren’t always be in coding, there are other ways too.

Finally, I have to tell you that don’t worry if your pull requests are rejected. They spend a lot time to improve their project. They know about their project more than us. Don’t worry about anything.

Stay strong, stay positive, and never give up.
― Roy T. Bennett, The Light in the Heart

You can contact and connect with me on Twitter.

Keep contributing to open source world!

--

--