: Keep the very first line under 50 characters. Leave the second line completely blank. Wrap all subsequent detailed paragraphs at 72 characters per line.
When you execute git commit , Git performs several background tasks: It creates the COMMIT_EDITMSG file.
Set a global template:
Refactor commit message handling and improve formatting
Improve commit message standards
The next time you stage a set of changes, close your terminal, type git commit , and take 60 seconds to write a message inside that COMMIT_EDITMSG buffer. Look at the diff. Write a subject line. Write a body. Save. Close.
if ! grep -q -E "$pattern" "$message_file"; then echo "ERROR: Commit message does not follow Conventional Commits format." echo "Expected: <type>(<scope>): <subject>" echo "Example: feat(auth): add OAuth2 provider" exit 1 fi
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin" Advanced Automation: Leveraging Git Hooks
For example, teams use this hook to check if a commit message starts with a valid Jira ticket identifier: COMMIT-EDITMSG
: Git populates this file with commented-out boilerplate text (lines starting with # ). These lines list the files you are committing, the files you left unstaged, and basic instructions.
#!/bin/sh # Get the commit message from the temporary file commit_msg_file=$1 commit_msg=$(cat "$commit_msg_file") # Regular expression for conventional commit format regex="^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?: .+" if ! echo "$commit_msg" | grep -Eq "$regex"; then echo "❌ Error: Commit message does not follow Conventional Commits format." echo "Example: feat(auth): add login validation" exit 1 fi Use code with caution. The prepare-commit-msg Hook
You do not have to settle for Git's default text editor. You can change which application opens COMMIT_EDITMSG and alter the helper text displayed inside it. Changing your default editor
If you don't like Vim, change your git editor to something more comfortable, like VS Code: git config --global core.editor "code --wait" . : Keep the very first line under 50 characters
show you which files are staged for commit, which are unstaged, and helpful reminders that "empty messages abort the commit." These comments are automatically stripped out by Git and will not appear in your final history. Why It Matters Using this file instead of the quick -m "message"
Typing git commit -m "Fix the thing in the service layer that was causing the race condition between the producer and consumer threads..." is error-prone. You must craft the message before the editor opens. The COMMIT_EDITMSG workflow allows you to open the file, look at the diff (via git status comments), then write the perfect message.
file provides the context needed to understand complex architectural decisions. Pro-Tips for Using COMMIT_EDITMSG Configure Your Editor : You can change which editor opens this file by running git config --global core.editor "code --wait" (for VS Code) or your preferred tool. Commit Templates : You can create a permanent template for your COMMIT_EDITMSG
Most developers never look inside this file. They see the editor window pop up, assume it’s just a blank text box, and type git commit -m "fix bug" . They are missing the point entirely. When you execute git commit , Git performs