Git Practices
So you're eager to get started with your project, that's great, but before you commit your first line of code, let's take a moment to understand some essential Git practices that will help you and your team collaborate effectively.
Table of Contents
- Framework
- Branching Strategy
- Commit Messages
- Pull Requests
- Code Reviews
- Merging
- Conflict Resolution
- Best Practices
Framework
We're using Git as our version control system, and we follow the GitFlow Workflow for our branching strategy. This means we have specific branches for development, features, releases, and hotfixes.
Branching Strategy
Here's a quick overview of our branching strategy:
Default Branch
We use master as our default branch, which always contains the latest stable release.
You won't be committing directly to master. Instead, you'll create feature branches for your work.
Development Branch
The develop branch is where all the feature branches are merged once they are complete and tested. This branch contains the latest development changes that are ready for the next release.
Feature Branches
Feature branches are created from the develop branch and are used for developing new features or making changes. The naming convention for feature branches is feat/your-feature-name.
Hotfix Branches
Hotfix branches are created from the master branch to quickly address critical issues in the production code. The naming convention for hotfix branches is hotfix/your-hotfix-name.
Branch Naming Convention
Use branch prefixes based on the type of work:
feat/<short-description>for new functionality.fix/<short-description>for bug fixes.docs/<short-description>for documentation-only updates.chore/<short-description>for maintenance/tooling tasks.hotfix/<short-description>for urgent production fixes.
Once you've completed your work on a feature or hotfix branch, you'll create a pull request to merge your changes back into the master and develop branches.
Commit Messages
Writing clear and concise commit messages is crucial for maintaining a clean project history.
Here are some guidelines for writing good commit messages:
- Follow Conventional Commits:
<type>(<scope>): <description>. - Keep the subject line concise (preferably <= 72 characters).
- Use lowercase
typevalues such asfeat,fix,docs,refactor,chore,ci. - Clearly explain what changed and why. Avoid vague messages like "Fix stuff" or "Update code."
- Focus on the intent of the change, not just the mechanics.
Conventional Commit Format
Use a clear type and optional scope:
type(scope): short descriptionExamples:
feat(auth): add JWT-based login endpoint
fix(session): prevent timeout on refresh
docs(readme): add local setup steps
docs(onboarding): clarify first-day checklist
chore(deps): update Vue to latest compatible version
chore(repo): clean up obsolete handbook assetsProvide Context
Provide context, reasoning, or details for the change.
Use bullet points or paragraphs for clarity, and wrap lines at ~72 characters for readability in tools like Git.
feat(auth): add user authentication endpoint
- Implement JWT-based authentication for API
- Add middleware for token validation
- Update README with setup instructionsInclude Metadata
We use Plane for tracking issues and tasks. Add task metadata in the commit footer:
feat(auth): add user authentication endpoint
Refs: T123If the task is completed in that commit, use:
fix(auth): handle expired refresh token
Done: T123Avoid Generic Messages
Avoid generic messages like "Fix stuff" or "Update code." Be specific about what was changed and why.
Messages like "WIP," "Fix," or "Changes" are unhelpful. Instead, specify the change (e.g., "Fix null pointer exception in user service").
Examples of Good and Bad Commit Messages
Good Examples:
feat(auth): implement user authenticationdocs(onboarding): add attendance instructionsfix(auth): resolve session timeout in login flow
- Resolve issue with session timeout
- Add unit tests for login functionalitydocs(readme): update installation instructions
- Add steps for setting up the development environment
- Include troubleshooting tipsdocs(remote-company): refine communication policy wordingrefactor(user-service): simplify dependency wiring
- Improve code readability and maintainability
- Remove deprecated methods
- Add comments for complex logicci(gitlab): run docs build in staging pipelinechore(deps): bump vitepress plugin versionschore(repo): remove legacy deployment notesBad Examples:
update authfix bugchangesUse The Right Verb
Use the right Conventional Commit type to describe intent:
feat: new functionality (e.g.,feat(profile): add user profile page)fix: bug fix (e.g.,fix(auth): prevent crash in login flow)docs: documentation-only changesrefactor: code changes without behavior changeci: CI/CD pipeline changeschore: maintenance tasks (dependencies, tooling, cleanup)revert: undo a previous commit
Pull Requests
Once you've completed your work on a feature or hotfix branch, it's time to create a pull request (PR) to merge your changes back into the develop and master branches.
If your PR addresses a specific Plane task, make sure to include the task ID in the PR title or description using the format T[task_id].
The feat/* branch should be merged into develop, and the hotfix branch should be merged into both master and develop.
Creating a Pull Request
- Push your
feat/*,fix/*,docs/*,chore/*, orhotfix/*branch to the remote repository. - Navigate to the repository on GitLab.
- Click on "Merge Requests" in the sidebar.
- Click on "New Merge Request."
- Select your source branch (
feat/*,fix/*,docs/*,chore/*, orhotfix/*) and target branch (develop/master). - Fill in the PR title and description, including any relevant Plane task IDs.
- Assign reviewers and set labels if necessary.
Code Reviews
Code reviews are an essential part of our development process. They help ensure code quality, share knowledge, and catch potential issues early.
Review Process
- Once a PR is created, assign at least one team member as a reviewer.
- Reviewers should thoroughly examine the code changes, checking for functionality, readability, and adherence to coding standards.
- Leave comments or suggestions for improvements directly on the PR.
- The author should address any feedback and make necessary changes.
- Once the reviewer is satisfied, they can approve the PR.
- The PR can then be merged into the target branch.
Review Guidelines
- Be respectful and constructive in your feedback.
- Focus on the code, not the person.
- Ask questions if something is unclear.
- Suggest improvements, but also acknowledge good practices.
- Ensure that the code adheres to our coding standards and best practices.
- Verify that the code is well-tested and that tests pass.
- Check for potential performance issues or security vulnerabilities.
- Ensure that the commit messages are clear and follow our guidelines.
Merging
Once a PR has been approved, it's time to merge the changes into the target branch.
Merging Process
- Ensure that the target branch is up to date with the latest changes.
- If there are any conflicts, resolve them before merging.
- Use the "Merge" button on the PR page to merge the changes.
- After merging, delete the feature or hotfix branch to keep the repository clean.
- If the PR was for a hotfix, ensure that the changes are also merged into the
developbranch.
Merge Strategies
For master branch merges, we use "Squash and Merge" to keep the commit history clean. This combines all commits from the feat/* branch into a single commit on the target branch.
For develop branch merges, we use "Merge Commit" to preserve the full history of changes. This allows us to see the individual commits made during feature development.
Conflict Resolution
Conflicts can occur when multiple people are working on the same codebase. Here's how to handle them:
- If you encounter a conflict while merging, Git will notify you of the files that are in conflict.
- Open the conflicting files and look for the conflict markers (
<<<<<<<,=======,>>>>>>>). - Manually resolve the conflicts by choosing which changes to keep or combining them as necessary.
- After resolving the conflicts, stage the changes using
git add <file>. - Commit the resolved changes with a clear message indicating that conflicts were resolved.
- Push the changes to the remote repository and update the PR if necessary.
- Notify the reviewers that the conflicts have been resolved and the PR is ready for review again.
Best Practices
- Regularly pull changes from the
developbranch to keep yourfeat/*branch up to date. - Write clear and concise commit messages.
- Create small, focused PRs that are easy to review.
- Always request a code review before merging.
- Address feedback promptly and professionally.
- Keep your branches organized and delete them after merging.
- Use Plane task IDs in commit footers and PRs to link work to specific tasks.
- Test your code thoroughly before creating a PR.
- Follow coding standards and best practices to maintain code quality.