Commit your code in style with git.emoji π
Have you ever get bored with the same old commit messages, all starting with “update”, “fix” or “feat”? Do you know that emojis are the latest advancement in human language and communication? They can convey emotions and ideas in a single character and make your messages alive! Think about it, even when aliens come to Earth, they will quickly understand the meaning of these little characters! π
New year, new you! Letβs leave boring commits in the past and embrace the magic of emojis to make every commit a celebration! π₯³β¨
Introduction
git.emoji is a tool written in Go that allows you to use emojis in your commit messages. It provides a simple command-line interface to help you select the right emoji for your commit. It will setup git hooks to commit with emoji, and can be used as a wrapper of git.
Whether you are fixing a bug, adding a new feature, or updating documentation, you can now express yourself with emojis!
Installation
To install git.emoji
, you need to have Go installed on your machine. You can download the latest version of Go from the official website. Once you have Go installed, you can install git.emoji
using the following command:
git clone https://github.com/connectlyai/git.emoji.git
cd git.emoji
./build.sh
Now you should have git.emoji
installed on your machine, usually at ~/go/bin/git.emoji
. Make sure to add this directory to your PATH
so you can use git.emoji
from anywhere.
Let’s check if it’s installed correctly:
$ which git.emoji
~/go/bin/git.emoji
And try running git.emoji
:
$ git.emoji
git.emoji - git commit with emoji
git.emoji is a tool to commit your changes with emoji.
It will setup git hooks to commit with emoji, and can
be used as a wrapper of git.
Setup
To start using git.emoji
, you need to set up the git hooks in your repository. You can do this by running the following command in your repository:
git.emoji setup-hooks
This command will set up the necessary git hooks to use git.emoji
for your commits. Now you can start committing with emojis!
Usage
Your first commit with emoji
Let’s start with a simple commit:
touch README.md
git add .
git.emoji commit -m "edit README"
This command will open a prompt for you to select an emoji for your commit message. You can choose from a list of emojis and add a message to describe your commit. Once you have selected an emoji and added a message, the commit will be made with the emoji and message.
--- π Please choose an emoji π ----------------------
1. Features π» β¨ -feat -ft
2. Bug Fixes π§ π -fix -fx
3. SDKs/Libraries π οΈ π¦ -sdk -lib -pkg -tenets
4. Breaking Changes π₯ π₯ -breaking -br -brk -break
5. Code Refactoring β»οΈ -refactor -rf -ref -rft
6. Infrastructure π³ -infra -if -in -inf
7. Tests π¨ π§ͺ -test -ts -tst
8. Chores π§Ό π§Ή -chore -ch -chr
9. Reverts β³ βͺ -revert -rv -rev -rvt
10. Releases π π -release -rl -rel -rls
11. Others π -other -ot -oth
HINT: You can use command line flag to choose the type:
git commit -feat -m 'message' # π» Features
git commit -ft -m 'message' # π» Features
git commit -ft1 -m 'message' # β¨ Features
git commit -ch -m 'message' # π§Ό Chore
git commit -ch1 -m 'message' # π§Ή Chore
Enter a number or abbr or emoji (1 | 1a | ft | ft1):
For example, if you want to commit a new feature, you can use input the number 1
or the abbreviation ft
select the Features
category and the π»
emoji. Each category has a list of emojis that you can choose from to describe your commit. To use the next emoji instead, you can enter 1a
or ft1
to select the β¨
emoji, and so on.
Commit with emoji from the command line
In addition to using the interactive prompt, you can also commit with an emoji directly from the command line. You can use the -<abbr>
flag to select the emoji for your commit. For example, to commit a new feature, you can use the following command:
git.emoji commit -feat -m "add new feature" # use the π» emoji for Features
git.emoji commit -ft -m "add new feature" # use the π» emoji for Features
git.emoji commit -ft1 -m "add new feature" # use the β¨ emoji for Features
This way, you can quickly commit your changes with emojis without going through the interactive prompt.
Use git.emoji
as a wrapper for git
If you don’t like to type git.emoji
every time you want to commit, you can alias git.emoji
as a wrapper for git
. Add the following line to your shell configuration file (e.g., .bashrc
, .zshrc
, .bash_profile
):
alias git=git.emoji
Now you can use git
as you normally would, and it will automatically use git.emoji
for your commits.
git commit -feat1 -m "add new feature" # use the β¨ emoji for Features
It works with rebase, merge, and other git commands
Not just committing, whenever you use git
commands that involve committing, such as rebase
, merge
, or cherry-pick
, if there is a commit message without emoji, git.emoji
will prompt you to select an emoji for the commit message. This way, you can ensure that all your commits are consistent and expressive.
Customize your emojis
You don’t have to use the default emojis provided by git.emoji
. You can always use your favourite emojis, either by input the emoji directly while commiting your changes or customize the emojis in your local emoji.config
file.
Currently, it supports two locations for the emoji.config
file:
<YOUR_REPOSITORY>/emoji.config
<YOUR_REPOSITORY>/.git/emoji.config
With the first way, you can customize and share the emojis with your team in the repository. With the second way, you can customize the emojis for your local repository only.
To start customizing your emojis, you can run this command:
git.emoji write-config
This will ask you where you want to save the emoji.config
file:
Current config file: /Users/i/ws/conn/git.emoji/.git/emoji.config
Where do you want to write the config file?
1. /Users/i/ws/conn/git.emoji/.git/emoji.config
2. /Users/i/ws/conn/git.emoji/emoji.config
Enter a number:
The config file will look like this:
[git.emoji "Features"]
icons = π» β¨
alias = feat ft
[git.emoji "Bug Fixes"]
icons = π§ π
alias = fix fx
[git.emoji "SDKs/Libraries"]
icons = π οΈ π¦
alias = sdk lib pkg tenets
[git.emoji "Breaking Changes"]
icons = π₯ π₯
alias = breaking br brk break
[git.emoji "Code Refactoring"]
icons = β»οΈ
alias = refactor rf ref rft
[git.emoji "Infrastructure"]
icons = π³
alias = infra if in inf
[git.emoji "Tests"]
icons = π¨ π§ͺ
alias = test ts tst
[git.emoji "Chores"]
icons = π§Ό π§Ή
alias = chore ch chr
[git.emoji "Reverts"]
icons = β³ βͺ
alias = revert rv rev rvt
[git.emoji "Releases"]
icons = π π
alias = release rl rel rls
[git.emoji "Others"]
icons = π
alias = other ot oth
Just edit the file, add your favourite emojis, create any categories you like, and save the file. Now you can use these emojis in your commits!
How it works
git.emoji
works by setting up git hooks in your repository to intercept the commit messages. When you make a commit, the git hook will call git.emoji
to prompt you to select an emoji for your commit message. Once you have selected an emoji, git.emoji
will add the emoji to your commit message and make the commit.
Under the hooks
The git hooks are set up in the .git/hooks
directory of your repository. If you look in this directory, you will see a bunch of hook files:
$ ls .git/hooks
applypatch-msg.sample post-commit pre-commit.sample prepare-commit-msg.sample
commit-msg post-merge pre-merge-commit.sample push-to-checkout.sample
commit-msg.sample post-rewrite pre-push.sample reference-transaction
fsmonitor-watchman.sample post-update.sample pre-rebase.sample update.sample
post-applypatch pre-applypatch.sample pre-receive.sample
post-checkout pre-auto-gc prepare-commit-msg
Whenever git runs a command that triggers a hook, it will execute the corresponding hook script. For example, when you make a commit, git will run the commit-msg
hook. This is where git.emoji
comes in. It provides a script that you can use as the commit-msg
hook to prompt you to select an emoji for your commit message.
By default, they are all empty sample shell scripts. After running git.emoji setup-hooks
, the commit-msg
hook in your repository will be updated to include the git.emoji
script. This script will call git.emoji
to prompt you to select an emoji for your commit message:
$ cat .git/hooks/commit-msg
#!/bin/bash
## START GIT.EMOJI
if [[ -x /Users/i/go/bin/git.emoji ]]; then
/Users/i/go/bin/git.emoji gmoji-commit-msg "$@" < /dev/tty || exit $?
fi
## END GIT.EMOJI
So you get the idea. Whenever you make a commit, the commit-msg
hook will call git.emoji
, which will prompt you to select an emoji for your commit message. Once you have selected an emoji, git.emoji
will add the emoji to your commit message by editing the file .git/COMMIT_EDITMSG
.
Another related hook is prepare-commit-msg
, which is called before the commit message editor is opened. This is where git.emoji
can automatically add an emoji to your commit message when you are doing a rebase, merge, or cherry-pick.
Conclusion
git.emoji brings a fresh and expressive way to commit your code by adding emojis to your messages. It enhances communication within your team by making commit intent clear and fun, whether youβre fixing bugs, adding features, or releasing updates. With its seamless integration into Git hooks and a customizable emoji configuration, itβs a practical tool to elevate your workflow.
So why stick to boring commit messages when you can make them vibrant and meaningful? Start your New Year and upgrade your commits with emojis! π
Let's stay connected!
Author
I'm Oliver Nguyen. A software maker working mostly in Go and JavaScript. I enjoy learning and seeing a better version of myself each day. Occasionally spin off new open source projects. Share knowledge and thoughts during my journey. Connect with me on , , , , or subscribe to my posts.