Skip to content

Latest commit

 

History

History
350 lines (265 loc) · 6.14 KB

File metadata and controls

350 lines (265 loc) · 6.14 KB

🔄 Git Workflow & Best Practices

📋 Pre-Commit Checklist

Before committing your code, ensure:

  • Code compiles without errors

    ./gradlew clean build
  • All tests pass

    ./gradlew test
  • Code follows formatting standards

    • Check .editorconfig settings
    • Use consistent spacing (2 spaces, not tabs)
  • No sensitive data in commit

    • No .env files
    • No API keys or secrets
    • No personal information
  • Documentation is updated

    • Update TODO.md with progress
    • Update README.md if feature is complete
    • Add JavaDoc for public methods

🌿 Branch Naming Convention

feature/<feature-name>    # New features
bugfix/<bug-description>  # Bug fixes
hotfix/<urgent-fix>       # Production hotfixes
refactor/<refactor-name>  # Code refactoring
docs/<doc-update>         # Documentation only
test/<test-addition>      # Test additions

Examples:

git checkout -b feature/messaging-service
git checkout -b bugfix/user-registration-validation
git checkout -b docs/api-documentation-update

💬 Commit Message Format

Structure

[Phase X] Type: Brief description

- Detailed change 1
- Detailed change 2
- Detailed change 3

Refs: #issue-number (if applicable)

Types

  • Feature: - New feature
  • Fix: - Bug fix
  • Refactor: - Code refactoring
  • Docs: - Documentation update
  • Test: - Test additions/updates
  • Chore: - Build/config changes

Examples

Good Commit Messages:

[Phase 1] Feature: Implement JWT authentication service

- Added JwtService with token generation
- Implemented token validation and expiration
- Added refresh token support
- Configured RS256 signing algorithm

Refs: #12
[Phase 1] Fix: Resolve user registration validation error

- Fixed email validation regex
- Added phone number format validation
- Updated error messages for clarity
[Phase 2] Feature: Create Conversation and Message entities

- Added Conversation entity with JPA mappings
- Added Message entity with status tracking
- Created database migrations V2 and V3
- Implemented repositories for both entities

Bad Commit Messages:

Fixed stuff
Updated code
WIP
...

🔄 Daily Git Workflow

1. Start Your Day

# Switch to main branch
git checkout main

# Pull latest changes
git pull origin main

# Create feature branch
git checkout -b feature/your-feature-name

2. During Development

# Check status frequently
git status

# Add files to staging
git add <specific-files>
# OR add all changed files
git add .

# Commit with descriptive message
git commit -m "[Phase X] Type: Description"

3. End of Day

# Push your branch
git push origin feature/your-feature-name

# If feature is complete, create PR on GitHub
# Otherwise, continue working tomorrow

4. Feature Complete

# Ensure all tests pass
./gradlew test

# Merge main into your branch (if needed)
git checkout main
git pull origin main
git checkout feature/your-feature-name
git merge main

# Resolve any conflicts, then push
git push origin feature/your-feature-name

# Create Pull Request on GitHub
# Request code review
# Merge after approval

🚫 What NOT to Commit

Never commit these files:

.env
.env.local
*.key
*.pem
*.p12
*.jks
application-local.yml
secrets/
*.log
node_modules/
build/ (except gradle wrapper)
.idea/ (IDE settings)

Check before committing:

# See what will be committed
git diff --cached

# Review changes file by file
git diff HEAD

🔧 Useful Git Commands

Undo Changes

# Discard changes in working directory
git checkout -- <file>

# Unstage files
git reset HEAD <file>

# Undo last commit (keep changes)
git reset --soft HEAD~1

# Undo last commit (discard changes)
git reset --hard HEAD~1

Branch Management

# List all branches
git branch -a

# Delete local branch
git branch -d feature/branch-name

# Delete remote branch
git push origin --delete feature/branch-name

# Rename current branch
git branch -m new-branch-name

Viewing History

# View commit history
git log --oneline --graph --decorate

# View changes in specific commit
git show <commit-hash>

# View file history
git log -- <file-path>

Stashing Changes

# Save changes temporarily
git stash

# List stashes
git stash list

# Apply most recent stash
git stash pop

# Apply specific stash
git stash apply stash@{0}

🎯 PR (Pull Request) Checklist

Before creating a PR:

  • Branch is up to date with main
  • All tests pass locally
  • Code follows project conventions
  • No merge conflicts
  • Documentation is updated
  • Commit messages are clear
  • No debug code or comments left

PR Title Format

[Phase X] Feature: Brief description

PR Description Template

## Description
Brief description of changes

## Changes Made
- Change 1
- Change 2
- Change 3

## Testing
- [ ] Unit tests added/updated
- [ ] Integration tests pass
- [ ] Manual testing completed

## Screenshots (if applicable)
Add screenshots here

## Checklist
- [ ] Code follows style guidelines
- [ ] Documentation updated
- [ ] No breaking changes
- [ ] Tests pass

🆘 Common Git Issues

Issue: Merge Conflicts

# Pull latest changes
git pull origin main

# Open conflicted files
# Resolve conflicts manually
# Look for <<<<<<, ======, >>>>>>

# After resolving
git add <resolved-files>
git commit -m "Resolved merge conflicts"

Issue: Committed Wrong Files

# Remove file from staging
git reset HEAD <file>

# Remove file from last commit
git rm --cached <file>
git commit --amend

Issue: Wrong Commit Message

# Amend last commit message
git commit --amend -m "New message"

📚 Learning Resources


Remember: Good git hygiene makes collaboration easier and keeps the project history clean! 🎉