Git Tutorial menu

GitHub Pull Requests

A pull request (PR) is a request to merge your branch into another branch on GitHub. It is how teams review and discuss code before it reaches main.

The Team Workflow

Most teams follow this simple flow:

  1. Pull the latest main.
  2. Create a branch for your task.
  3. Commit your work on that branch.
  4. Push the branch to GitHub.
  5. Open a pull request.
  6. A teammate reviews it and suggests changes.
  7. When approved, the PR is merged into main.

main always stays working, and every change is checked by at least one other person.

Step by Step

Example

bash
git switch main
git pull
git switch -c add-contact-page

Make your changes and commit:

Example

bash
git add contact.html
git commit -m "Add contact page with map and phone number"
git push -u origin add-contact-page
Output
remote: Create a pull request for 'add-contact-page' on GitHub by visiting:
remote:      https://github.com/ayesha-dev/my-site/pull/new/add-contact-page
To https://github.com/ayesha-dev/my-site.git
 * [new branch]      add-contact-page -> add-contact-page

Open the link GitHub prints, or click Compare & pull request on the repository page.

Writing a Good Pull Request

  • Title: what the PR does, like "Add contact page"
  • Description: why the change is needed and how to test it
  • Keep it small: a PR with 100 changed lines gets a better review than one with 3,000
  • Link the issue it fixes by writing "Closes #12" in the description

Reviewing a Pull Request

On the PR page, the Files changed tab shows the diff. Reviewers can:

ActionMeaning
CommentAsk a question or suggest something on a line
ApproveThe change looks good to merge
Request changesSomething must be fixed first

To fix requested changes, just commit again on the same branch and push. The PR updates automatically:

Example

bash
git commit -am "Fix phone number format on contact page"
git push

Be kind in reviews. Comment on the code, not the person, and explain why you suggest a change.

Merging the PR

When approved, click Merge pull request on GitHub. GitHub offers three ways:

OptionResult
Create a merge commitKeeps all commits plus a merge commit
Squash and mergeCombines all PR commits into one clean commit
Rebase and mergePuts the commits on top of main without a merge commit

Then update your local copy and clean up:

Example

bash
git switch main
git pull
git branch -d add-contact-page
Output
Deleted branch add-contact-page (was 6e0a2f9).

Forks: Contributing to Other Projects

You cannot push to someone else's repository. To contribute to an open-source project:

  1. Click Fork on GitHub to make your own copy of the repository.
  2. Clone your fork, create a branch, commit and push to your fork.
  3. Open a pull request from your fork to the original repository.

The project's maintainers then review and merge it. Contributing to open source is a great way to build experience and your GitHub profile.

Issues

GitHub Issues are a to-do list for the project: bug reports, feature ideas and tasks. Each has a number like #12, and a PR that says "Closes #12" closes the issue automatically when merged.

Exercise

Exercise

What is a pull request on GitHub?

Learn Git with a teacher

Join the Full Stack Development course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp