Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 3.23 KB

File metadata and controls

27 lines (20 loc) · 3.23 KB

10. Best Practices

Commit Messages

  1. 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.
  2. 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."
  3. 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.
  4. Reference Issues or Tickets: If your project uses an issue tracker, reference the issue number in the commit message. For example: "Fix bug #123."
  5. 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

  1. Branch Early and Often: As soon as you start working on a new feature or fix, create a branch. This keeps the develop and master branches clean and ensures that unfinished features don't disrupt the main codebase.
  2. 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.
  3. 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.
  4. 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

  1. Communicate: Always communicate with your team about what you're working on. This helps in avoiding overlapping work and merge conflicts.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.