The Git PR-commit message

I've made life easier for myself, and maybe my coworkers, by writing commit messages in a way that works for pull requests on GitHub.

By on

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


Visit a page that isn't the homepage, then click login. After logging
in you should be redirected to the page you started on.


This uses the new login process because it's more stable than the
old process (which is slated for retirement).


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:

  1. ProTip: avoid using # for headings, as Git will interpret them as comments and remove them from the commit text. [return]