π§ Git Workflow & Conventional CommitsΒΆ
This guide covers our Git workflow and commit message standards for the CLOE Toolbox project.
πΏ Git WorkflowΒΆ
Branch StrategyΒΆ
We use a feature branch workflow integrated with Azure DevOps:
graph LR
A[main] --> B[feature/auth-module]
B --> C[feat: add login]
C --> D[test: add auth tests]
D --> E[docs: update API docs]
E --> F[merge to main]
F --> G[v1.2.0]
A --> H[hotfix/security-patch]
H --> I[fix: security vulnerability]
I --> J[merge to main]
J --> K[v1.2.1]
ποΈ Branch Naming ConventionΒΆ
Use descriptive branch names that clearly indicate the purpose:
| Branch Type | Pattern | Example |
|---|---|---|
| π Features | feature/description |
feature/user-authentication |
| π Bug Fixes | fix/description |
fix/memory-leak-processor |
| π Documentation | docs/description |
docs/api-reference |
| π§ Maintenance | chore/description |
chore/update-dependencies |
| π¨ Hotfixes | hotfix/description |
hotfix/security-patch |
π Conventional CommitsΒΆ
We follow the Conventional Commits specification for consistent commit messages.
π― Commit Message FormatΒΆ
π Commit TypesΒΆ
| Type | Description | Example |
|---|---|---|
feat |
β¨ New feature | feat: add user login functionality #1234 |
fix |
π Bug fix | fix: resolve memory leak in data processor #1235 |
docs |
π Documentation | docs: add API reference for auth module #1236 |
style |
π Code style changes | style: format code according to PEP 8 #1237 |
refactor |
β»οΈ Code refactoring | refactor: simplify user validation logic #1238 |
test |
π§ͺ Adding tests | test: add unit tests for auth module #1239 |
chore |
π§ Maintenance | chore: update dependencies to latest versions #1240 |
perf |
β‘ Performance improvements | perf: optimize database query performance #1241 |
ci |
π· CI/CD changes | ci: add automated security scanning #1242 |
build |
π¦ Build system changes | build: update build configuration #1243 |
π Scope (Optional)ΒΆ
Specify the component or module affected:
feat(auth): add OAuth2 integration #1234
fix(database): resolve connection timeout issue #1235
docs(api): update endpoint documentation #1236
π‘ Commit ExamplesΒΆ
fix: resolve memory leak in data processor #1235
The data processor was not properly cleaning up resources
after processing large datasets, causing memory usage to grow
continuously.
- Add proper resource cleanup in finally blocks
- Implement garbage collection hints
- Add memory usage monitoring
Fixes #1235
π Azure DevOps IntegrationΒΆ
π Linking Work ItemsΒΆ
Always link commits to Azure DevOps work items using the ID:
# Feature commits
git commit -m "feat: implement data validation #1234"
# Multiple work items
git commit -m "fix: resolve authentication issues #1234 #1235"
# Different linking keywords
git commit -m "feat: add new endpoint (closes #1234)"
git commit -m "fix: memory leak (fixes #1235)"
git commit -m "docs: API reference (resolves #1236)"
π·οΈ Keywords for Work Item ActionsΒΆ
| Keyword | Action | Usage |
|---|---|---|
#1234 |
Link | Links commit to work item |
fixes #1234 |
Close | Closes work item when merged |
closes #1234 |
Close | Closes work item when merged |
resolves #1234 |
Close | Closes work item when merged |
π οΈ Git Best PracticesΒΆ
π¦ Commit GuidelinesΒΆ
- π― Atomic Commits: Each commit should represent a single logical change
- π Clear Messages: Write descriptive commit messages for future developers
- π Link Work Items: Always include Azure DevOps work item IDs
- π Reasonable Size: Keep commits focused and reasonably sized
π Before CommittingΒΆ
- π§ͺ Run Tests: Ensure all tests pass
- π§Ή Check Code Quality: Run linting and formatting
-
π Update Documentation: Update relevant documentation
-
π Review Changes: Double-check what you're committing
π Git Flow CommandsΒΆ
π Starting New WorkΒΆ
# Create and switch to feature branch
git checkout -b feature/your-feature-name
# Link initial commit to work item
git commit -m "feat: initial setup for new feature #1234"
πΎ Regular DevelopmentΒΆ
# Stage specific files
git add src/module.py tests/test_module.py
# Commit with conventional format
git commit -m "feat: add data validation logic #1234"
# Push to remote
git push origin feature/your-feature-name
π Preparing for PRΒΆ
# Rebase on latest main
git fetch origin
git rebase origin/main
# Interactive rebase to clean up commits (if needed)
git rebase -i origin/main
# Force push (only for feature branches)
git push --force-with-lease origin feature/your-feature-name
π Advanced Git TechniquesΒΆ
π§ Interactive RebaseΒΆ
Use interactive rebase to clean up commit history before creating PRs:
# Rebase last 3 commits interactively
git rebase -i HEAD~3
# Common rebase commands:
# pick = use commit
# reword = use commit, but edit message
# edit = use commit, but stop for amending
# squash = use commit, but meld into previous commit
# drop = remove commit
π― Cherry-pickingΒΆ
Apply specific commits to other branches:
# Apply commit to current branch
git cherry-pick <commit-hash>
# Apply multiple commits
git cherry-pick <commit1> <commit2>
π Useful Git CommandsΒΆ
# View commit history with graph
git log --oneline --graph --decorate
# Search commit messages
git log --grep="feat"
# Find when a bug was introduced
git bisect start
git bisect bad HEAD
git bisect good <known-good-commit>
# Show changes in a commit
git show <commit-hash>
# Compare branches
git diff main..feature/branch-name
Pro Tips
- Use
git commit --amendto modify the last commit message - Create aliases for frequently used commands in
.gitconfig - Use
git stashto temporarily save work when switching branches - Set up VS Code as your default Git editor for better commit message writing
Important Reminders
- Never force push to
mainbranch - Always include work item IDs in commit messages
- Keep commit messages under 72 characters for the first line
- Use present tense in commit messages ("add" not "added")