Over the past couple of years I’ve found myself writing commit messages that are intended to be used as both a commit message and a PR (pull request). This is mostly because GitHub will use the commit message from the first commit in a PR as the PR text.
This has changed my overall approach to commit messages in a way that seemed worth documenting. Specifically, I have merged tips for a better commit message with writing a great pull request, and how to write a commit message, so everything those posts mention are still valid.
Here’s a commit message that has been modified to include PR-specific information:
Redirect user to the requested page after login Users were being redirected to the home page after login, which is less useful than redirecting to the page they had originally requested before being redirected to the login form. * Store requested path in a session variable * Redirect to the stored location after successfully logging in the user Testing ------- Visit a page that isn't the homepage, then click login. After logging in you should be redirected to the page you started on. Notes ----- This uses the new login process because it's more stable than the old process (which is slated for retirement). Resolves: https://trello.com/path/to/relevant/card
As you may have noticed, I now use Markdown in my commit messages. I do this so that GitHub will render the PR nicely without any additional work on my part1.
There are a few benefits of using the hybrid PR-commit approach:
- It’s DRY: there is only one source for the PR, and it is forever a part of the timeline because it’s in a commit message. Even if you move away from GitHub, you will still have a log of all your PRs.
- It’s efficient: because of the way that GitHub reads in the PR from your commit message, you don’t have to type it out multiple times.
- It’s pretty: since GitHub formats PRs with Markdown, you don’t have to make any modifications to the PR. It will look great right away without changing anything.
- ProTip: avoid using
#for headings, as Git will interpret them as comments and remove them from the commit text. [return]