Join the community!
Visit our GitHub or LinkedIn page to join the Tilburg Science Hub community, or check out our contributors' Hall of Fame!
Want to change something or add new content? Click the Contribute button!
Best Practices for Git Commits
When collaborating on projects, it is important to have conventions for making Git Commits to ensure consistency in the way of working. In this building block we outline some of the most common best practices for Git Commits. In the end we will be able to answer the questions:
- How large should a commit be?
- How often should we make a commit?
- How to write better commit messages?
1. Relate every commit to a specific change
Each commit should correspond to an issue or branch. Thus, if there are two different issues to be solved, each of them should have a commit. This way, smaller and specific commits are easier to follow and makes the progress easier to track.
2. Commit often
It is better to commit small and frequent changes, than piling up more tasks and committing them rarely. But remember to always relate them to an issue or branch.
3. Commit only completed changes
Although it is good practice to make often and rather small commits, they should always contain completed tasks.
4. Write meaningful commit messages
- The message can have a short summary and a description - in general, the summary should be less than 50 characters; the summary should be separated from the description with an empty line
- Keep it short - stick to the main idea
- Use the imperative of the present tense - e.g. “fix”, “change”
- The message should answer these questions - What was the reason of the change? How has it changed?
5. Check changes before commiting
Make sure to carefully test or check the implemented changes before making a commit. This avoids complications and more future work.
- Link every commit to an issue or branch
- Commit often but only completed changes
- Verify changes before committing
- Write concise commit messages in imperative present tense