GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - brajkowski/branch-commit-msg: A git commit-msg hook that automatically inserts a matched pattern from the active branch name to the commit message.

BranchesTags
Open more actions menu

Latest commit

 

History

850 Commits
850 Commits

Folders and files

NameName
Last commit message
Last commit date
.claude
.claude
 
 
.github
.github
 
 
.husky
.husky
 
 
.yarn/releases
.yarn/releases
 
 
src
src
 
 
test
test
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.lintstagedrc
.lintstagedrc
 
 
.mergify.yml
.mergify.yml
 
 
.npmrc
.npmrc
 
 
.nvmrc
.nvmrc
 
 
.prettierignore
.prettierignore
 
 
.prettierrc.json
.prettierrc.json
 
 
.releaserc.json
.releaserc.json
 
 
.yarnrc.yml
.yarnrc.yml
 
 
CLAUDE.md
CLAUDE.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.mjs
build.mjs
 
 
eslint.config.mjs
eslint.config.mjs
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
yarn.lock
yarn.lock
 
 

Repository files navigation

branch-commit-msg

Build npm:latest npm:beta codecov semantic-release: angular

Overview

branch-commit-msg is a git commit-msg hook that extracts a configurable regex pattern from the current branch and reformats the final commit message to the configured format.

Installation

With no dependency:

npx branch-commit-msg install

With husky:

npm install -D branch-commit-msg
echo 'npx branch-commit-msg-hook "$1"' > .husky/commit-msg

Uninstall

With no dependency:

rm .git/hooks/commit-msg

With husky:

Remove npx branch-commit-msg-hook "$1" from .husky/commit-msg and run:

npm uninstall branch-commit-msg

Usage

After installation, create a .commitmsgrc.json file at the root of your project and configure how you would like to reformat your final commit message based on elements of the active branch name:

// .commitmsgrc.json

{
  /*
    Regex group pattern to extract from branch name.
      - ex: "(sc)-?[0-9]+"
  */
  "extractPattern": string,

  /*
    Whether the extractPattern is case-sensitive.
      - ex: true
  */
  "extractPatternMatchCase": boolean,

  /*
    Final output format for the commit message.

    Formatting Placeholders:
      %b0: access the entire matched pattern from the branch name
      %b1: access the first matched group pattern from the branch name
      %bn: access the 'n'th matched group pattern from the branch name
        - ex: "%b6" accesses the 6th matched group pattern
      %m: the original commit message

    Pipes:
      lower: applies lower casing to the formatting placeholder
        - ex: "$b2 | lower"
      upper: applies upper casing to the formatting placeholder
        - ex: "%m | upper"
  */
  "commitMsgFormat": string
}

After your .commitmsgrc.json is configured, start making commits!

Configuration Examples

Preface commit message with a Shortcut ticket number:

{
  "extractPattern": "sc-[0-9]+",
  "extractPatternMatchCase": false,
  "commitMsgFormat": "%b0 - %m"
}
# Current branch: SC-123456/my-new-feature
git commit -m "added a thing"
git log -1 --pretty=%B
# Output: SC-123456 - added a thing

Suffix and format a commit message with a JIRA ticket:

{
  "extractPattern": "SOMEPRJ-[0-9]+",
  "extractPatternMatchCase": false,
  "commitMsgFormat": "%m (%b0 | upper)"
}
# Current branch: feature/someprj-123456
git commit -m "added a thing"
git log -1 --pretty=%B
# Output: added a thing (SOMEPRJ-123456)

Go crazy with group matching:

{
  "extractPattern": "(some).*(complex[0-9-]+).*(branch)",
  "extractPatternMatchCase": false,
  "commitMsgFormat": "%m | upper to %b1 | upper %b2 %b3 | lower"
}
# Current branch: some/CoMpLEX-123-5/BRANCH
git commit -m "added a thing"
git log -1 --pretty=%B
# Output: ADDED A THING to SOME CoMpLEX-123-5 branch

Development

Prerequisites

  • Docker installation (for integration and end-to-end (e2e) testing)
  • Node.js (LTS) runtime
  • Yarn installation

Install Dependencies

$ yarn install

Test

$ yarn test[:unit|:integration|:e2e|:smoke]

Build

$ yarn build

About

A git commit-msg hook that automatically inserts a matched pattern from the active branch name to the commit message.

Topics

branchcommitcommit-messagecommit-msggithookmessage

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.