How to make your first pull request on GitHub

Sachin Maurya
6 min readMay 21, 2021

--

Photo by Roman Synkevych on Unsplash

Before diving deep in lets learn about some terminology that we are going to use.

What is Forking ?

A fork is a copy of a project folder (repository) into your Github account or onto your desktop if you use Github on your Desktop. This allows you to freely experiment with changes without affecting the original project.

What is Pull Request?

Pull requests let you tell others about changes you’ve pushed to a branch in a repository on GitHub

For instance, a user Sam forks a repository of Sachin and makes changes to that repository. Now Sam can make a pull request to Sachin but it’s up to Sachin to accept or decline it. It’s like “Would you please, Sachin pull my changes?”.

Let’s make our first pull request!

If you’re not much familiar with Git & GitHub, please review this article

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.

$ 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

Now we need to create the new branch as we cannot directly commit to the main branch.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]

Now you can see that the new branch is created and we have also change our branch from master to myContribution.

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 .

You can also just specify the file name which you are changing using command git add [FILE NAME]

Now commit those changes using the git commit command:

$ git commit -m "adding my name in .md file"

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

The remote name is a short-hand label for a remote repository. “origin” is the conventional default name for the first remote and is usually where you push to when you don’t specify a remote for git. You can set up more than one remote for your local repo and you use the remote name when pushing to them.

$ 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

While using GitHub and contributing to various apps, it is important we keep our fork repository updated with the master repository as there might be various changes done by various contributors and if we have that updated, it will help us in our future issues and contributions and also use the updated version of the project. Here is the official definition of syncing fork with master.

Getting the latest changes in the master repository after you have forked it without losing the current changes you have made in your local repository.

Step 1: Run the following command in your terminal to see the current configured remote repository in your fork

Step 2: Run the following command

$ git remote add upstream https://github.com/(original_owner_or_organisation/(original_repository).git

This particular command will help you add the upstream which means the link to master repository from which you have forked.

Step 3 : Check your remote now by running the following command again

$ git remote -v

It will show something like this, which indicates your own local repository and also your master repository.

Step 4 : Fetch the changes from the upstream with following command

$ git fetch upstream

Now, that you’ve set the upstream, it’s time to fetch the changes from the upstream(master repository) that have been made since the time you forked. But make sure, you are in your master branch or any main branch before you run this command.

Step 5 : Merge the fetched changes

$ git merge upstream/master

Now it’s all left to merge the changes that you’ve have fetched from your master to the local repository.

If you are familiar with git then you might be knowing about git pull you can read more about it here.

From the Git documentation for git pull

In its default mode, git pull is shorthand for git fetch followed by git merge FETCH_HEAD.

8. Delete the unnecessary branch

Once your purpose is accomplished, you can delete the branch.

$ git branch -d [Branch Name]

If you have made it this far then ,Congratulation you have learned How to make your first pull request but you might be thinking How can I search for the repository to make the pull request don’t worry I got you covered.

Here are some of the website and repository to look for some good first issue .

Conclusion

Open Source is for everyone it’s not that if you are not good at coding you can’t contribute to the project you can still contribute by making changes to docs and README.md files. If you are new to some project you can ask them what the issue is about and what are the changes required they will definitely help you.

Reference

Code for Cause [If you are interested in Open Source and want to learn more about it do check out “Code for Cause” youtube channel]

Have any queries you can contact me on

Twitter , Github , Linkedin

Will meet in next blog until then stay curious.✌️

--

--

No responses yet