DEV Community

Abner Soares Alves Junior
Abner Soares Alves Junior

Posted on

Faster Conventional Commits Messages

Conventional Commits is a specification to help creating an organized commit history.

This is not a tutorial explaining what it is, but a simple tip for automate some pieces when you are working with it.

The slow way πŸšΆβ€β™€οΈ

In your daily workflow, the team commits use to follow a pattern using the prefixes, like: feat:, chore(API):, fix:. It's become repetitive and can be optimized.

The faster way πŸƒβ€β™€οΈ

Here is a simple solution for my case, but this can be extended in many ways to your workflow.

function gitCommit() {
  git add .
  git commit -m "$1: $2"
}

alias gchore="gitCommit chore"
alias gfeat="gitCommit feat"
alias gfix="gitCommit fix"
alias gwip="gitCommit wip"
Enter fullscreen mode Exit fullscreen mode

The function takes 2 args, one is the prefix you want to be added, second is the message.

In my case, what I most use are these prefixes, so I've created an alias for every single one.

Now when I want to add all and commit I just run

$ g<prefix> "message to be commited"
Enter fullscreen mode Exit fullscreen mode

Going Further

Another good improvement is using oh-my-zsh combo with Git Plugin.
It brings a lot of aliases for other languages, other CLIs, like Heroku, Ruby, etc.

Using the Git Plugin the above function could be converted to:

function gitCommit() {
  gaa
  gcmsg "$1: $2"
}
Enter fullscreen mode Exit fullscreen mode

Use your imagine and you can include other things as you need.

Latest comments (0)