• One Tip a Week
  • Posts
  • One Tip a Week: Git Aliases for Conventional Commits

One Tip a Week: Git Aliases for Conventional Commits

This week’s tip of the week is a set of git aliases I use to leverage Conventional Commits. If you’re new to git aliases read up more on git aliases in the official git documentation.

Before I added these aliases, I would need to write a git command like this if I was for example committing some documentation changes

git commit -m "docs: awesome docs commit"

This is definitely doable as a command, but we’re lazy right? You can add the following Conventional Commits git aliases by running:

# Add chore alias
git config --global alias.chore '!chore() { git commit -m "chore: $1"; }; chore'

# Add fix alias
git config --global alias.fix '!fix() { git commit -m "fix: $1"; }; fix'

# Add feat alias
git config --global alias.feat '!feature() { git commit -m "feat: $1"; }; feature'

# Add featb alias
git config --global alias.featb '!featurebreak() { git commit -m "feat!: $1"; }; featurebreak'

# Add test alias
git config --global alias.test '!test() { git commit -m "test: $1"; }; test'

# Add docs alias
git config --global alias.docs '!docs() { git commit -m "docs: $1"; }; docs'

Now when I have a commit that is for documentation for example, I run git docs “awesome docs commit”

❯ git docs "awesome docs commit"
[main 424d146] docs: awesome docs commit
 1 file changed, 1 insertion(+)
 create mode 100644 guide.md

And this is what the commit looks like. Notice it’s prefixed with docs:

* 424d146 (HEAD -> main) docs: awesome docs commit
* afe5442 (origin/main, origin/HEAD) added some more stuff to uses page

That’s it! Short and sweet. Until the next one!