Functions and Classes in Python

Collaborating using Pull Requests

Overview:

  • Teaching: 10 min
  • Exercises: 10 min

Questions

  • What is a pull request?
  • How do I create a pull request?
  • How do I manage or accept a pull request?

Objectives

  • Understand that pull requests allow you to contribute to repositories you don't have write access to.
  • Know how to issue pull requests.
  • Understand how to manage a pull request to repositories you own.

What is a pull request?

If you don't have write access to the remote repository you won't be able to push your commits and branches directly to it. To collaborate you request that someone who does have have write access pull your commits and merge them.

This can be done from the command-line with git request-pull, however the user interface and user experience is much better on one of the git hosting profiders like GitHub. In fact, the social and collaborative aspect of GitHub is resposible for a lot of their succecss.

How do pull requests work?

Here’s the workflow:

  • Fork the project

    • Click the fork icon in the top right
  • Create a topic branch from master.

    • In the drop down next to "Branch:master" drop it down and type the name of your new branch
  • Make some commits to improve the project.

    • you can use the GitHub builtin editor, click on the crayon icon
  • Open a Pull Request on GitHub.

    • Go to the pull requests tab, then click on "New Pull Request"
  • Discuss, and optionally continue committing.

  • The project owner merges or closes the Pull Request.

    • Go to the pull requests tab, you will see the open pull requests, click merge

Exercises

Exercise 1

  • The first user plays the role of the repository owner (hereafter "A") provides the second user playing the role of the contributor (herefter "B") with the repository URL
  • B forks the repository
  • B creates a branch called, for example bugfix
  • B makes a change to a file
  • B commits the change to their branch
  • B goes to the pull request tab and creates a new pull request, by comparing A's master brach to their branch
  • A gets an email notifying them of the pull request
  • A goes to the pull request tab in their repository and merges the open pull request.

Exercise 2

  • switch roles and repeat exercise 1

Key Points:

  • Pull requests allow you to contribute to projects that you do not have write access to
  • Pull requests allow owners to check that contributions:
    • Don't break the code base
    • Maintain standards e.g. coding style, structure guidelines