10. Best Practices
Commit Messages
Be Concise but Descriptive: A commit message should be brief but should effectively convey the change's purpose. Ideally, the main message should be no more than 50 characters, followed by a more detailed description if necessary.
Use the Imperative Mood: Write your commit message as if you're giving a command. For example, "Add login feature" or "Fix bug in payment gateway."
First Line is Crucial: The first line of your commit message should provide a summary of the changes. If more detail is needed, leave a blank line after the first line and then continue with a more detailed description.
Reference Issues or Tickets: If your project uses an issue tracker, reference the issue number in the commit message. For example: "Fix bug #123."
Avoid Ambiguity: Be clear about what you did and why, especially if the change fixes a bug or introduces a new feature.
When to Branch and Merge
Branch Early and Often: As soon as you start working on a new feature or fix, create a branch. This keeps the
develop
andmaster
branches clean and ensures that unfinished features don't disrupt the main codebase.Merge After Peer Review: Before merging a feature or fix branch into the main branches, it's a good practice to have someone else review your code. Platforms like GitHub and GitLab offer "Pull Request" or "Merge Request" features to facilitate this.
Keep Branches Short-Lived: Branches should be temporary and only exist while actively developing a feature or fix. Once the change is merged into the main branch, delete the feature or fix branch.
Regularly Pull from Upstream: If collaborating with others, regularly pull changes from the main repository to stay updated. This helps in reducing merge conflicts later.
Collaborating with Others
Communicate: Always communicate with your team about what you're working on. This helps in avoiding overlapping work and merge conflicts.
Respect the History: Avoid rewriting the public history. If you're working on a shared branch, avoid using commands like
git rebase
which can alter commit history. This can create confusion for other collaborators.Use Pull/Merge Requests: When working in a team, use pull or merge requests to introduce changes. This provides an opportunity for code review and ensures that multiple eyes have vetted the changes.
Resolve Conflicts Promptly: If there's a merge conflict, address it immediately. The longer a conflict remains unresolved, the harder it can become to address, especially if other changes are made in the interim.
Stay Consistent: Whether it's coding style, branching strategy, or commit message format, consistency is key. It makes collaboration smoother and the project more maintainable.
Educate and Onboard: Ensure that every member of the team understands the version control practices you're using. A well-informed team is less likely to make mistakes or develop inefficient workflows.
Remember, while these best practices provide a solid foundation, the most important thing is to find workflows and strategies that best fit your team's needs and the specifics of your project. Adapt and adjust as necessary.
Last updated