Create a Simple Pull Request on GitHub in 7 Steps

GitHub Basics 101

Nifla Fareed
LinkIT
4 min readDec 7, 2020

--

Image by “OpenClipart-Vectors” from “Pixabay”

GitHub is a code-hosting site that supports git version control and collaboration in project management. GitHub provides many tools which we can use to support collaborating in group projects.

GitHub Pull Requests

Pull Requests are the basic way to contribute to group projects or open-source projects on GitHub. By making a pull request you can suggest your changes to your team members and ask them to review your contribution and integrate it into the main branch or repository.

Follow the steps given below to make a simple pull request to the main repository of your project.

Step 1: Clone the main repository

First, you have to pull the main repository or branch to your local machine so that you can work with it locally.

To clone, Go to the main repository, click on the code button and copy the URL as indicated below.

Screenshot by Author

Once you copied the URL, open the command prompt and select the directory in which the repository to be downloaded, After that run the command given below:

git clone <URL>

Step 2: Create a New Branch and Make Changes

After cloning the repository go to the project folder (use cd command here)

Now you can add your changes to the files in the way you want. Before making changes it is a good practice to create a separate branch and then to start working on your modifications.

To create a new branch run the below command:

git checkout –b <branch_name>

Once you run the above command you will be moved to that branch, so that you can make changes or modifications to the code.

Step 3: Add Files

Use the below command to check what changes you made before adding it to the repository.

git status
Screenshot by Author

Files that are not added to the main repository will be indicated in red color as shown above. To add those files you can use any of the following commands:

1. git add <file_name>     // add a file2. git add <directory_name> //add a directory3. git add .                //add all the changes

Using the first two commands is more effective than the other as we can add the particular file we prefer to add to the main repository.

Screenshot by Author

The added but not committed files will be indicated in green color as shown above.

Step 4: Commit Files

However, the git add command doesn’t affect the main repository until we commit the changes we added already, to record all the changes you should run the command given below:

git commit –m “<message>”

Always keep the message meaningful and precise when committing changes.

To check the commit history you can use any of the following commands:

git log   //displays all of the commits in a repository’s history
git log --oneline //displays one commit per line

Step 5: Set your remote repository

To make the pull request we have to set up the main repository as our remote repository. To set up a remote repository run the command given below:

git remote add <remote_name> <main_repository_URL>

When setting up the remote repository you can give any name as the remote name.

You can get the URL of your remote/main repository as shown below

Screenshot by Author

Step 6: Push your changed files to GitHub

After setting up the remote, safely push your changes to GitHub. To make a pull request run the command given below:

git push <remote_name> <branch_name>

Note that you must add your branch name along with the remote name while running the above command, or else it will replace the main branch.

Step 7: Create a pull request

Go to the main repository on GitHub click the button ‘Compare & pull request’

Screenshot by Author

Add any comment about the changes or modifications you have made, and click “Create pull request”

Screenshot by Author

Thank you for reading, hope you found this article helpful!

--

--

Nifla Fareed
LinkIT
Writer for

Software Engineer @ IFS | Graduated from University of Moratuwa, Sri Lanka