18

I want to create a template that will appear automatically on each pull request.

This can either be a note or a comment. Ideally it will display guidelines as to reviewing the pull request:

- [ ] Have you done x?
- [ ] Have you done y?
- [ ] Have you done z?

Can anyone suggest a way of doing this?

1

6 Answers 6

14

Yes, it is now possible.

Add a file named pull_request_template.md to the root of your project:

- [ ] Have you done x?
- [ ] Have you done y?
- [ ] Have you done z?

You can also create a template for issues using the same convention. Just name the file issue_template.md.

Source: https://github.com/blog/2111-issue-and-pull-request-templates

2
  • 2
    It appears that the template has to be in the project's default branch in order to be used. Eg, suppose the default branch is master, but you want to do a PR from some_feature to beta. When you start the PR, the interface shows the PR going to master. If your template is in master, it will be used, but if it's in beta, it won't be used, even after you change the selection for the PR base. Nov 10, 2016 at 15:00
  • 1
    The template can also go into the .github/ folder, to avoid clutter at the root level Nov 19, 2017 at 2:47
4

GitHub now support pull request template through PULL_REQUEST_TEMPLATE.md file

Pull request template sample

https://help.github.com/articles/creating-a-pull-request-template-for-your-repository/

4

GitHub does not allow you to create a template for pull requests created on it's website.

The solution we use is to create pull requests using the github api via the hub command. We wrap this in a script called makePR that does something like:

#!/bin/bash
URL=$(hub pull-request -F PR-template.md)
echo "New PR created at $URL"
open $URL

(untested - our actual script does a lot more - I've left out parameters I think you don't need)

The open command will open the URL in the default browser on MacOS, you may need to adjust this for other platforms. Once it is open, you can edit the title in your web browser.

3
  • This answer is obsolete.
    – ThomasW
    Sep 5, 2017 at 4:31
  • @ThomasW This simple version is obsolete, but the real version inserted more dynamic stuff into the PR description, depending on the name of the branch, including links to the issue on JIRA etc.
    – rjmunro
    Sep 5, 2017 at 11:03
  • 1
    I should have said, the first sentence is obsolete.
    – ThomasW
    Sep 7, 2017 at 7:24
2

Unfortunately, this is not possible with GitHub alone. Good news, GitHub now supports this! Check out the accepted answer.

Also, GitHub has a pretty cool (and somewhat hidden) feature that you can use to link potential contributors to some contribution information whenever they create a new issue or pull request.

From Contributing Guidelines on The Github Blog:

We've tried making this easy for everyone. As a maintainer, all you have to do is add a CONTRIBUTING file (or CONTRIBUTING.md if you're using Markdown) to the root of your repository. Then we will add a link to your file when a contributor creates an Issue or opens a Pull Request.

GitHub screenshot

Now, as soon as your collaborators start participating, they can easily find the guidelines you'd like them to follow.

1

There is a chrome extension that claims to do it here: https://github.com/sprintly/pull-request-template-chrome-extension

Unfortunately, I couldn't get it to work, but the code looks simple enough to figure out and fix - I expect it's something simple that has broken due to github or chrome being updated.

It only seems to allow you to use a single template for every github pull request that you make, rather than pull in the correct template for the current repository.

1
0

Right now it is possible to create templates for issues and pull requests. It can be described in the ISSUE_TEMPLATE, or PULL_REQUEST_TEMPLATE files in the repository root or in the .github folder.

You can find more information here https://github.com/blog/2111-issue-and-pull-request-templates

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.