How to write git message for commit? #102837
-
Select Topic AreaQuestion BodyHello, everybody. What is the best practice for git messages for collaboration? I have to discuss about this in team meeting. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
A good Git commit message is crucial for effective collaboration and maintaining a high-quality codebase. It provides context, clarity, and understanding of the changes made to the code, which helps other developers understand the purpose and reasoning behind those changes. Anatomy of a Git commit message Subject Line Body Footer Best practices for writing a good Git commit message Keep it concise and meaningful Example: Fix typo in README.md Use imperative mood in the title Example: Add new feature to dashboard Use conventional commits Example: feat: add new feature to dashboard Provide context in the body Example: Fix typo in README.md The typo was causing confusion for new users, so I corrected it to improve readability. Use the footer for metadata and related issues Example: Add new feature to dashboard Resolves #123 This feature adds a new widget to the dashboard that displays real-time data about user activity. By following these best practices, you can write clear and concise commit messages that are meaningful and informative to other developers. This can improve collaboration and make it easier to maintain your codebase over time. Tools and tips to improve Git commit messages Using Git hooks to enforce commit message format To set up a Git hook to enforce a commit message format, you can create a pre-commit hook that checks the message and rejects the commit if it doesn't meet the specified format. For example, you can enforce a message format that includes a short summary of the changes, followed by a more detailed Using tools like commitizen or git-cz to simplify commit message writing To use commitizen, you can install it globally using npm:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for posting in the GitHub Community, @topbot-1995 ! We're happy you're here. You are more likely to get a useful response if you are posting your question in the applicable category, the Discussions category is solely related to conversations around the GitHub product Discussions. I've gone ahead and moved it for you. Good luck! |
Beta Was this translation helpful? Give feedback.
A good Git commit message is crucial for effective collaboration and maintaining a high-quality codebase. It provides context, clarity, and understanding of the changes made to the code, which helps other developers understand the purpose and reasoning behind those changes.
Anatomy of a Git commit message
A Git commit message typically consists of three parts: the subject line, the body, and the footer.
Subject Line
The subject line is the first and most important part of a commit message. It should be a brief summary of the changes made in the commit. The subject line should be no more than 50 characters long and should be written in the imperative tense (e.g., Add feature X rather than …