Never Lose PR Context: Using Bitbucket Commit Message Templates
By configuring Bitbucket's commit message templates, teams can automatically embed PR titles, descriptions, IDs, and other metadata into Git commit messages, ensuring that valuable review information persists in the repository history even if the hosting platform changes.
Background
Recently we discussed a seemingly simple but important question: how to ensure valuable information in PRs does not get lost over time and tool changes.
Although we use Bitbucket for daily collaboration, we may migrate to GitHub, GitLab, etc. The hosting platform may change, but Git itself as the core history will likely remain.
PR description, background, solution ideas, and key discussion, if stored only in the PR tool, are likely to disappear after platform migration; these details should be part of the commit message.
Discussed Solutions
Manually record solution in git commit -m — easy to miss or incomplete.
Use a NEWS file like pip projects — suitable for generating release notes, not for recording motivations or reasons.
Force team to write content in Jira tickets — tool fragmentation, hard to understand history in code context.
We finally decided to use Bitbucket's Commit Message Templates to write PR descriptions directly into Git commits.
Bitbucket Commit Message Templates
Bitbucket can automatically generate commit messages when merging a PR and allows inserting useful information via a template. Documentation link: Pull request merge strategies - Bitbucket Server.
GitLab also has a similar feature, but GitHub seems not to. GitLab commit templates: https://docs.gitlab.com/user/project/merge_requests/commit_templates/
You can use the following variables in the template:
title: PR title
id: PR ID
description: PR description
approvers: currently approved reviewers
fromRefName / toRefName: source/target branch names
fromProjectKey / toProjectKey: source/target project
fromRepoSlug / toRepoSlug: source/target repository
crossRepoPullRequestRepo: source repository for cross‑repo PR
How We Use It
In Bitbucket repository settings, configure the merge commit template: Repository settings → Merge strategies → Commit message template.
After configuration, when merging a PR, Bitbucket automatically inserts the PR title, description, ID, and other metadata into the final merge commit message.
This ensures that regardless of future tool changes, the key PR information remains in Git history.
Example screenshots:
Conclusion
Although a small change, it protects the context of code changes from a process perspective, turning PRs from temporary containers into permanent parts of Git history.
If you use Bitbucket, give this feature a try. Let commit messages become records of decisions and evolution, not just code changes.
References
Pull request merge strategies - Bitbucket Server: https://confluence.atlassian.com/bitbucketserver0819/pull-request-merge-strategies-1416826109.html
DevOps Engineer
DevOps engineer, Pythonista and FOSS contributor. Created cpp-linter, commit-check, etc.; contributed to PyPA.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.