DEV Community

Cover image for Git Conventional Commits:
Rajnish
Rajnish

Posted on

Git Conventional Commits:

What is Git Conventional Commits?

Git Conventional Commits is a structured way of writing commit messages that follow a specific format. It standardizes how developers describe changes, making version history more readable and automating processes like changelog generation and semantic versioning.

A conventional commit message follows this pattern:

type(scope): description
Enter fullscreen mode Exit fullscreen mode

For example:

feat(auth): add JWT authentication for secure login
fix(ui): resolve alignment issue in navbar
Enter fullscreen mode Exit fullscreen mode

Why is it Important?

  1. Improves Readability – Makes it easier to understand what changes were made and why.
  2. Enhances Collaboration – Team members can quickly scan commits without confusion.
  3. Automates Versioning – Helps in semantic versioning by identifying breaking changes, features, and fixes.
  4. Simplifies Release Notes – Changelogs can be auto-generated from commit messages.

How Does It Improve Our Standards?

  • Consistency – Following a uniform format ensures clean commit history.
  • Traceability – Each commit explains its purpose, helping in debugging.
  • Better CI/CD Integration – Tools like semantic-release and commitizen use structured commits for automation.

How Does It Make Us Stand Out?

Using conventional commits makes a developer look more professional and disciplined. Employers and team leads value clear documentation in commit history. It also facilitates better collaboration in open-source projects where clarity is crucial.

Real-Time Examples of Conventional Commits

1. Feature Addition

feat(button): add primary button component
- Created a reusable button component
- Supports different variants like primary and secondary
- Added unit tests for the button functionality
Enter fullscreen mode Exit fullscreen mode

2. Bug Fix

fix(login): resolve incorrect password validation
- Fixed regex issue causing false negatives
- Updated error message for better clarity
- Tested different edge cases
Enter fullscreen mode Exit fullscreen mode

3. Code Refactoring

refactor(auth): simplify login function
- Removed redundant API calls
- Consolidated validation logic
- Improved code readability without changing functionality
Enter fullscreen mode Exit fullscreen mode

4. Performance Improvement

perf(api): optimize user search query
- Added indexing to improve lookup speed
- Reduced query response time by 50%
- Implemented caching for frequently searched users
Enter fullscreen mode Exit fullscreen mode

5. Style Fixes

style(css): fix indentation in stylesheets
- Corrected inconsistent spacing
- Removed unused CSS classes
- Ensured all styles follow the project’s guidelines
Enter fullscreen mode Exit fullscreen mode

6. Adding or Modifying Tests

test(profile): add unit tests for profile updates
- Wrote test cases for edit profile functionality
- Covered edge cases for input validation
- Ensured all tests pass before merging
Enter fullscreen mode Exit fullscreen mode

7. Build System Update

build(dependencies): update React to v18
- Updated package.json and package-lock.json
- Resolved compatibility issues with third-party libraries
- Tested application for breaking changes
Enter fullscreen mode Exit fullscreen mode

8. CI/CD Configuration Change

ci(github-actions): add automated testing workflow
- Integrated Jest tests into GitHub Actions
- Set up automatic test execution on pull requests
- Configured Slack notifications for build failures
Enter fullscreen mode Exit fullscreen mode

9. Operational Changes

ops(deployment): automate database backups
- Implemented cron job for daily backups
- Stored encrypted backups in cloud storage
- Set up alert system for failed backups
Enter fullscreen mode Exit fullscreen mode

10. Documentation Update

docs(readme): update installation instructions
- Added steps for setting up the project locally
- Clarified database configuration requirements
- Included troubleshooting section
Enter fullscreen mode Exit fullscreen mode

11. Miscellaneous Changes

chore(gitignore): add .env to ignored files
- Prevented sensitive environment variables from being committed
- Updated .gitignore to include log files
- Cleaned up unnecessary files from the repository
Enter fullscreen mode Exit fullscreen mode

12. Merging Branches

merge(feature-branch): merge new feature into main
- Resolved conflicts in App.js
- Ensured all tests pass before merging
- Reviewed changes for consistency
Enter fullscreen mode Exit fullscreen mode

13. Reverting a Commit

revert(auth): rollback OAuth2 integration
- Encountered critical security issues with OAuth implementation
- Reverted changes and restored previous authentication method
- Documented findings for future improvements
Enter fullscreen mode Exit fullscreen mode

Conclusion

Adopting Git Conventional Commits improves code quality, collaboration, and automation. It ensures a well-maintained repository with clear commit history, making life easier for developers, reviewers, and CI/CD processes. By following this structured approach, we elevate our development standards and stand out as disciplined professionals in the industry.

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

If you found this post helpful, please leave a ❤️ or a friendly comment below!

Okay