Git Commit Etiquette

05/2024

Navigating Git's version control landscape is essential for any developer, but often, the art of crafting clear commit messages gets lost in the shuffle. In this post, I'll provide a cheat sheet on writing effective Git commit messages.

Common Commit Types

feat: A new feature.
fix: A bug fix.
docs: Documentation-only changes.
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.).
refactor: A code change that neither fixes a bug nor adds a feature.
perf: A code change that improves performance.
test: Adding missing tests or correcting existing tests.
chore: Changes to the build process or auxiliary tools and libraries such as documentation generation.
ci: Changes to our CI configuration files and scripts (examples: CircleCi, SauceLabs).
build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm).
revert: Reverts a previous commit.
init: Initial commit.
release: Create a release commit.
wip: Work in progress. Not a complete commit, still in development.

Example Commit Messages

feat: feat(component): add Header component
    - Adds a new feature, such as a new component.

fix: fix(auth): resolve login issue
    - Fixes a bug, like resolving a login issue.

docs: docs(README): update installation instructions
    - Updates documentation, such as installation instructions in the README file.

style: style(main): reformat code according to linting rules
    - Changes code formatting without affecting functionality.

refactor: refactor(api): improve data fetching logic
    - Refactors code to improve structure or readability without changing its behavior.

perf: perf(api): optimize data processing for speed
    - Improves performance, such as optimizing data processing.

test: test(button): add unit tests for Button component
    - Adds or updates tests, such as unit tests for a component.

chore: chore(deps): update dependency versions
    - Changes to the build process or auxiliary tools, like updating dependencies.

ci: ci(circleci): update CircleCI config
    - Changes to CI configuration files.

build: build(webpack): update Webpack config
    - Changes to the build system or dependencies.

revert: revert: revert commit 1234abcd
    - Reverts a previous commit.

init: init: initial project setup
    - Initial commit for setting up a project.

release: release: release version 1.0.0
    - Commits for releasing a new version.

wip: wip: start implementing feature X
    - Indicates a work-in-progress commit.

By using these commit types, you can create a well-structured and readable commit history that makes it easier for your team to understand the changes. This practice is particularly useful when generating changelogs, performing code reviews, or debugging. Each commit message provides clear information about what was changed and why, which is invaluable for maintaining a project over time.