Commit-editmsg New! Jun 2026
COMMIT_MSG_FILE=$1
Inside your repository’s .git/hooks directory, you will find scripts that Git can run at specific points. The commit-msg hook is directly tied to COMMIT_EDITMSG . This script receives the path to the COMMIT_EDITMSG file as its first argument. You can write a script (in Bash, Python, Node.js, etc.) that reads the file, validates the message against your 50/72 rules, and rejects the commit if the format is wrong.
You can find this file in the .git folder at the root of your project: path/to/your/repo/.git/COMMIT_EDITMSG COMMIT-EDITMSG
Understanding the lifecycle of COMMIT_EDITMSG can be a lifesaver in specific scenarios:
While it might seem like a minor technical detail, COMMIT_EDITMSG is where you should practice good "Git hygiene" using the : COMMIT_MSG_FILE=$1 Inside your repository’s
This hook runs before the editor opens. Teams use it to inject dynamic content into the COMMIT_EDITMSG template automatically. For instance, a script can read your current Jira branch name ( feature/PROJ-1234-login ) and pre-populate the file with the ticket ID: [PROJ-1234] . 2. commit-msg
#!/bin/sh MSG_FILE="$1" # Git passes .git/COMMIT_EDITMSG as $1 if ! head -1 "$MSG_FILE" | grep -qE "^(feat|fix|docs): "; then echo "ERROR: Commit message must follow Conventional Commits format" exit 1 fi You can write a script (in Bash, Python, Node
Now create ~/.gitmessage.txt :
.git/COMMIT_EDITMSG
If you want to customize your workflow further, let me know: Which or IDE do you use for development?
Your default Git editor (set by $EDITOR , $GIT_EDITOR , or your global Git config) then automatically opens this file.