Git Workflow
This is my Git branching strategy and commit rules.
Commit Message Rules (Conventional Commits)
Basic Format
<type>(<scope>): <subject>
<body>
<footer>Required elements:
type: Change type (required)scope: Change scope (optional)subject: Change summary (required, within 50 characters)
Type Categories
| Type | Description | Example |
|---|---|---|
feat | New feature | feat(auth): add JWT authentication |
fix | Bug fix | fix(user): resolve null pointer exception |
docs | Documentation changes | docs(readme): update installation guide |
style | Code formatting (no functional changes) | style(user): apply ktlint formatting |
refactor | Code refactoring | refactor(order): extract payment logic |
test | Add/modify test code | test(user): add UserService unit tests |
chore | Build, config file changes | chore(deps): upgrade spring boot to 3.2 |
perf | Performance improvement | perf(query): optimize database query |
Scope Writing Guide
Scope specifies the changed module/feature:
| |
Subject Writing Rules
- Imperative present tense: “add” (O), “added” (X), “adds” (X)
- Lowercase start: “Add feature” (X), “add feature” (O)
- No period: “Add feature.” (X), “Add feature” (O)
- Within 50 characters: Keep it concise
| |
Body Writing (Optional)
Explain complex changes in the Body:
feat(user): add user profile update API
- Add PUT /api/v1/users/{id} endpoint
- Implement validation for profile data
- Add unit tests for UserService.updateProfile()
Changes were made to support user profile editing feature
requested in issue #123.Footer Writing (Optional)
Specify issue numbers, Breaking Changes:
feat(auth): migrate to OAuth2
BREAKING CHANGE: JWT authentication is replaced with OAuth2.
All existing tokens will be invalid.
Closes #456
Fixes #789Commit Unit Rules
Principle: Atomic Commits
One commit = One logical change
| |
Commit Size Guide
| Commit Size | Description | Example |
|---|---|---|
| Too small | Meaninglessly separated | git commit -m "add import" |
| Appropriate | One logical change | git commit -m "feat(user): add User entity" |
| Too large | Multiple features at once | git commit -m "feat: add user and order features" |
WIP (Work In Progress) Commits
Intermediate work commits should be squashed later:
| |
Branching Strategy
Branch Types
main # Production deployment branch
βββ develop # Development integration branch
βββ feature/* # Feature development branch
βββ bugfix/* # Bug fix branch
βββ hotfix/* # Emergency fix branch
βββ release/* # Release preparation branchBranch Naming
| |
Workflow Process
1. Feature Development
| |
2. Pull Request Creation
PR Template:
| |
3. Code Review
Reviewer checklist:
- Does commit message follow Conventional Commits format?
- Are commits atomic? (one commit = one logical change)
- Does it follow coding conventions?
- Are tests written?
- Are Breaking Changes documented if any?
4. Merge Strategy
| |
Git Hooks (Automatic Validation)
pre-commit (Pre-commit validation)
| |
commit-msg (Commit message validation)
| |
Conflict Resolution
| |
Security
1. .gitignore Configuration
Essential .gitignore settings to prevent committing sensitive information:
| |
2. Credential Management
| |
3. Removing Already Committed Sensitive Information
| |
4. Validate Sensitive Information with Pre-commit Hook
| |
5. Enable GitHub Secret Scanning
GitHub automatically detects sensitive information:
- Settings β Security β Code security and analysis
- Enable Secret scanning
- Enable Push protection (recommended)
Collaboration
1. Code Review Guide
Reviewer role:
| |
Reviewee role:
| |
2. Automatic Validation of Conventional Commits
commitlint configuration:
| |
3. Enhanced PR Template
.github/pull_request_template.md:
| |
4. Protected Branch Settings
Protect main/develop branches on GitHub:
| |
Forbidden Practices
Strictly Forbidden
- β Direct push to main branch: Only merge through PR
- β Force push to shared branches: develop, main, etc.
- β Meaningless commit messages: “update”, “test”, “asdf”
- β Large binary file commits: Use Git LFS
- β Committing sensitive information: passwords, API keys, tokens
- β Merge without review: Minimum 1 approval required
- β Merge with failing tests: Only merge after CI/CD passes
Cautions
- β οΈ WIP commits: Must squash before PR
- β οΈ Merge commits: Use Squash and Merge or Rebase and Merge
- β οΈ Modifying commit messages: Don’t modify already pushed commits
- β οΈ Large PRs: Consider splitting if over 500 lines (difficult to review)
Checklist
Before commit:
- Is commit message in Conventional Commits format?
- Is one commit one logical change?
- Is Subject within 50 characters?
- Using imperative present tense?
- Do tests pass?
- No sensitive information included?
- Is .gitignore properly configured?
Before PR:
- Are all commits in Conventional Commits format?
- Have WIP commits been squashed?
- Do all tests pass?
- Is code review ready?
- Is PR description clear? (what, why, how)
- Have you completed self-review?
- Have you updated related documentation?
During Code Review:
- Does functionality meet requirements?
- Does it follow coding conventions?
- Are there no security vulnerabilities?
- Is test coverage sufficient?
- Is there no performance degradation?