💌 Easy-to-add Git hook that forces you to start every commit message with an emoji
Once you install this, whenever you try to commit and your message doesn't start with an emoji, your commit will fail and you'll be prompted to amend it. You can bypass it by adding --no-verify
to git commit
.
Lots of people seem interested in using emoji in Git commit messages, for various reasons. You can do this in some consistent way to communicate stuff, or you can just do it to add fun to the world (or both).
Emoji bring a lot of light to my life. Do I really want them in every commit message? I don't know; let's find out.
No other tool did exactly what I wanted here, so I thought I'd play around in the wild mire of zero width joiners and fulfill them myself:
- ✨ Emoji are unicode (no shortcodes!)
- 🏄🏽♀️ Set it and forget it (Git hooks are simple.
package.json
scripts are simple.)
- If your project has a package.json
- If your project doesn't have a package.json (but Node is installed on your machine)
The chillest way to install this tool is to use Husky. 🐶
Run npm install -D husky && npm install -D commit-msg-must-use-emoji
.
(yarn add -D husky && yarn add -D commit-msg-must-use-emoji
probably works too.)
Then add a commitmsg
script so your package.json
looks like:
{
"...
"scripts": {
...
"commitmsg": "commit-msg-must-use-emoji",
...
},
...
}
🎉
(Note that this configuration format is for Husky ^0.14.3; version 0.15.x requires a different format, which is easy to migrate to. Using 0.15.x may give a peer dependency error, since it's still in prerelease, but you can probably do it.)
You can require this package and test a commit message string or a commit message filename (Husky stores it in process.env.GIT_PARAMS
while a general Git hook node script will provide it as process.argv[2]
):
const startsWithEmoji = require('commit-msg-must-use-emoji');
// e.g.
const messageString = 'Update code';
const messageFilename = '/Users/me/project/.git/COMMIT_EDITMSG';
if (!startsWithEmoji.testString(messageString)) {
console.error('😡')
}
// or
if (!startsWithEmoji.testFile(messageFilename) {
console.error('😿');
}
🎉
You can install this package globally (npm install -g commit-msg-must-use-emoji
or yarn global add commit-msg-must-use-emoji
) and then, as long as you're on a Unix machine and don't already have a commit-msg
Git hook, cd
to your repository and try
echo '#!/usr/bin/env sh
commit-msg-must-use-emoji $1' > ./.git/hooks/commit-msg && \
chmod +x ./.git/hooks/commit-msg
🎉
If you want to add this to an existing commit-msg
shell script, adding commit-msg-must-use-emoji $1
somewhere in there will probably work. If you're on Windows, I'm not sure.
Feel free. Issues and pull requests are open.
Thanks to all the emoji lovers, but interacting with the work of @notwaldorf, emojineer extraordinaire, has probably done the most to get me excited about emoji recently.