Git Workflow & Commit Standards
This document outlines the Git workflow and commit standards for the Magiclogger project.
Git Hooks
The project uses Husky to manage Git hooks for enforcing code quality and commit standards:
- pre-commit: Runs linting and formatting on changed files
- commit-msg: Validates commit message format
- pre-push: Runs tests before pushing to remote
- prepare-commit-msg: Automatically applies commit template
These hooks are automatically installed when you run npm install
.
Commit Message Format
All commit messages must follow the Conventional Commits format:
<type>(<scope>): <description>
[optional body]
[optional footer(s)]
Types
feat
: A new featurefix
: A bug fixdocs
: Documentation changesstyle
: Code style changes (formatting, etc.)refactor
: Code changes that neither fix bugs nor add featuresperf
: Performance improvementstest
: Test additions or correctionsbuild
: Changes to build system or dependenciesci
: Changes to CI configurationchore
: Other changes that don't modify src or test files
Scope
The scope is optional and should be the name of the component affected (e.g., logger
, colors
, types
).
Description
- Use the imperative, present tense: "change" not "changed" nor "changes"
- Don't capitalize the first letter
- No period (.) at the end
Creating Commits
You have two options for creating commits:
Option 1: Interactive Commit (Recommended for Beginners)
npm run commit
This runs Commitizen, which will guide you through creating a properly formatted commit message with interactive prompts.
Option 2: Standard Git Commit
git commit
This will open your default editor with a commit template. Fill in the template according to the instructions.
You can also commit directly with a message:
git commit -m "feat(logger): add custom color method"
But be sure to follow the conventional commit format, as it will be validated by the commit-msg hook.
Workflow Best Practices
-
Create feature branches:
git checkout -b feature/my-feature
-
Make small, focused commits:
- Each commit should represent a single logical change
- Keep commits small and focused on a specific task
-
Push your branch:
git push origin feature/my-feature
-
Create a Pull Request to merge your changes into the main branch
-
Delete the branch after it has been merged
Example Workflow
# Create a new branch
git checkout -b feature/add-progress-bar
# Make your changes
# ...
# Stage your changes
git add .
# Create a commit with guided prompts
npm run commit
# OR
git commit
# Push your branch
git push origin feature/add-progress-bar
# Create a PR on GitHub/GitLab
Troubleshooting
If you encounter issues with Git hooks:
-
Ensure hooks are executable:
chmod +x .husky/pre-commit .husky/commit-msg .husky/pre-push .husky/prepare-commit-msg
-
Temporarily bypass hooks (use sparingly):
git commit --no-verify -m "your message"
-
If your commit is rejected due to formatting issues:
npm run format
npm run lint:fix