Pull Requests

Last updated on 2025-04-06 | Edit this page

Overview

Questions

  • What are pull requests for?
  • How can I make a pull request?

Objectives

  • Define the terms fork, clone, origin, remote, upstream
  • Understand how to make a pull request and what they are useful for

Callout

Pull requests are a great way to collaborate with others using github. Instead of making changes directly to a repository you can suggest changes to a repo. This can be useful if you don’t have permission to modify a repository directly or you want someone else to review your changes.

On GitHub, in your planets repo, click on the “Pull Requests” tab.

Then click “New pull request”. Alternatively, GitHub will see your new branch with recent changes and will prompt you to “Compare & pull request”. Click this button to also be taken to the new pull request page.

Make sure that the “base” branch is main and the “compare” branch is pythondev.

Next, we need to give our PR a title. By default, your PR will get the title from your last commit. We can leave this as is.

We can leave a note in the PR description, like:

“The python analysis was faster than the bash analysis, so I am merging only the python analysis to main”.

Click “Create pull request”.

Your planets repo should now have 1 pull request. This is the phase where you would normally request a reviewer, who can leave comments on your code. In repos that you do not own, your PR will need to be approved by a codeowner before you can merge it. Since you are the codeowner, we can go ahead and click “Merge pull request”.

Go back to the “Code” tab and make sure you are on the “main” branch. You should now see an “analysis.py” file.

Let’s go back to VS Code. Checkout the main branch, and look at the files and history:

BASH

$ git checkout main
$ git log --oneline

OUTPUT

e98a594 (HEAD -> main, origin/main) Discuss concerns about Mars' climate for Mummy
33d27e2 Add concerns about effects of Mars' moons on Wolfman
7e1e559 Start notes on Mars as a base

The analysis file is not on “main” yet. This is because we need to first pull the changes we made with the Pull Request from the remote repository.

BASH

$ git pull
$ git log --oneline

OUTPUT

d980f78 (HEAD -> main, origin/main) Merge pull request #1 from vlad/pythondev
d5f2565 (origin/pythondev, pythondev) Wrote and tested python analysis script
e98a594 Discuss concerns about Mars' climate for Mummy
33d27e2 Add concerns about effects of Mars' moons on Wolfman
7e1e559 Start notes on Mars as a base

Now our main branch is up to date.

Deleting branches


Now that we’ve merged the pythondev into main, these changes exist in both branches. This could be confusing in the future if we stumble upon the pythondev branch again.

We can delete our old branches so as to avoid this confusion later. We can do so by adding the -d flag to the git branch command.

BASH

git branch -d pythondev

OUTPUT

Deleted branch pythondev (was x792csa1).

And because we don’t want to keep the changes in the bashdev branch, we can delete the bashdev branch as well

BASH

$ git branch -d bashdev

OUTPUT

error: The branch 'bashdev' is not fully merged.
If you are sure you want to delete it, run 'git branch -D bashdev'.

Since we’ve never merged the changes from the bashdev branch, git warns us about deleting them and tells us to use the -D flag instead.

Since we really want to delete this branch we will go ahead and do so.

BASH

git branch -D bashdev

OUTPUT

Deleted branch bashdev (was 2n779ds).

Finally, we can also delete the pythondev branch on GitHub. Click on “Branches”, and to delete the pythondev branch click the trashcan icon to the right of the branch name.

Key Points

  • Pull requests suggest changes to repos where you don’t have privileges