Git - Collaboration Workflows
Advanced
Successful collaboration requires more than knowing Git commandsβyou need proven workflows. This guide covers the most effective team development strategies used by professional software teams.
Popular Git Workflows
Different workflows suit different team sizes, release schedules, and project types:
Workflow | Team Size | Release Style | Complexity |
---|---|---|---|
Centralized | Small | Continuous | Low |
Feature Branch | Small-Medium | Regular | Medium |
GitFlow | Medium-Large | Scheduled | High |
GitHub Flow | Any | Continuous | Low |
GitLab Flow | Medium | Environment-based | Medium |
GitHub Flow
Simple, continuous deployment workflow popular in agile teams:
GitHub Flow principles:
1. main branch is always deployable
2. Create feature branches from main
3. Push early and often
4. Open pull request when ready
5. Deploy from feature branch for testing
6. Merge to main after review
7. Deploy main immediately
GitHub Flow Implementation
Step 1: Create feature branch
# Always start from latest main
git switch main
git pull origin main
# Create descriptive feature branch
git switch -c feature/user-authentication
Step 2: Work and commit regularly
# Make meaningful commits
git add .
git commit -m "Add login form component"
git add .
git commit -m "Implement password validation"
# Push early for backup and visibility
git push -u origin feature/user-authentication
Step 3: Open pull request
# Open PR via GitHub UI or CLI
gh pr create --title "Add user authentication" \
--body "Implements login/logout with session management"
# Or push and follow GitHub's prompt
git push origin feature/user-authentication
Step 4: Review and deploy testing
# Deploy feature branch to staging
git push origin feature/user-authentication:staging
# After review approval, merge
gh pr merge --squash
Step 5: Clean up
# Delete feature branch after merge
git switch main
git pull origin main
git branch -d feature/user-authentication
git push origin --delete feature/user-authentication
GitFlow Workflow
Structured workflow for teams with scheduled releases:
GitFlow branches:
main β Production-ready code, tagged releases
develop β Integration branch, latest development
feature/* β Individual features
release/* β Release preparation
hotfix/* β Production fixes
GitFlow Implementation
Initialize GitFlow:
# Install git-flow extensions (optional)
brew install git-flow-avh # macOS
apt install git-flow # Ubuntu
# Initialize GitFlow
git flow init
# Or manually create branches
git branch develop main
Feature development:
# Start feature (git-flow)
git flow feature start user-profile
# Or manually
git switch -c feature/user-profile develop
# Work on feature
git add .
git commit -m "Add profile model"
# Finish feature (git-flow)
git flow feature finish user-profile
# Or manually
git switch develop
git merge --no-ff feature/user-profile
git branch -d feature/user-profile
Release process:
# Start release
git flow release start v1.2.0
# Or manually
git switch -c release/v1.2.0 develop
# Prepare release
git commit -m "Bump version to 1.2.0"
# Finish release
git flow release finish v1.2.0
# Or manually
git switch main
git merge --no-ff release/v1.2.0
git tag -a v1.2.0 -m "Release 1.2.0"
git switch develop
git merge --no-ff release/v1.2.0
git branch -d release/v1.2.0
Hotfix process:
# Critical bug in production
git flow hotfix start critical-fix
# Or manually
git switch -c hotfix/critical-fix main
# Fix the bug
git commit -m "Fix critical security vulnerability"
# Finish hotfix
git flow hotfix finish critical-fix
# Or manually
git switch main
git merge --no-ff hotfix/critical-fix
git tag -a v1.2.1 -m "Hotfix 1.2.1"
git switch develop
git merge --no-ff hotfix/critical-fix
git branch -d hotfix/critical-fix
Pull Request Best Practices
Creating Effective Pull Requests
PR title and description template:
Title: [Feature] Add user authentication system
Description:
## What
Implements complete user authentication with login/logout functionality.
## Why
Enables user-specific features and content personalization.
## How
- Added User model with password hashing
- Created login/logout endpoints
- Implemented session management
- Added authentication middleware
## Testing
- Unit tests for User model
- Integration tests for auth endpoints
- Manual testing of login flow
## Screenshots
[Include screenshots of UI changes]
## Checklist
- [x] Tests added/updated
- [x] Documentation updated
- [x] No breaking changes
- [x] Follows coding standards
PR Review Process
Review checklist:
Code Quality:
- [ ] Code follows project conventions
- [ ] No code smells or anti-patterns
- [ ] Proper error handling
- [ ] No security vulnerabilities
Functionality:
- [ ] Features work as described
- [ ] Edge cases handled
- [ ] No regressions introduced
- [ ] Performance impact acceptable
Testing:
- [ ] Tests cover new functionality
- [ ] All tests pass
- [ ] Test quality is good
- [ ] Integration tests included
Documentation:
- [ ] README updated if needed
- [ ] API documentation updated
- [ ] Comments explain complex logic
Team Collaboration Patterns
Forking Workflow (Open Source)
Contributor workflow:
# 1. Fork repository on GitHub
# 2. Clone your fork
git clone [email protected]:yourusername/project.git
cd project
# 3. Add upstream remote
git remote add upstream [email protected]:originalowner/project.git
# 4. Create feature branch
git switch -c feature/awesome-feature
# 5. Work and commit
git commit -m "Add awesome feature"
# 6. Push to your fork
git push origin feature/awesome-feature
# 7. Open pull request from your fork to upstream
# 8. Keep fork updated
git fetch upstream
git switch main
git merge upstream/main
git push origin main
Shared Repository Workflow
Team member workflow:
# All team members have push access
git clone [email protected]:company/project.git
# Standard feature branch workflow
git switch main
git pull origin main
git switch -c feature/new-feature
# Work...
git push origin feature/new-feature
# Open PR
# Merge after review
Code Review Strategies
Review Types
Review Type | When | Focus |
---|---|---|
Self Review | Before submitting PR | Obvious issues, formatting |
Peer Review | Standard PR process | Code quality, functionality |
Architecture Review | Major changes | Design, patterns, performance |
Security Review | Security-sensitive code | Vulnerabilities, compliance |
Review Guidelines
For reviewers:
DO:
β
Be constructive and respectful
β
Explain the "why" behind suggestions
β
Acknowledge good code
β
Focus on important issues first
β
Test the changes locally if needed
DON'T:
β Be overly nitpicky about style
β Make personal attacks
β Block PRs for minor issues
β Approve without understanding
β Let PRs sit too long
Conflict Resolution
Preventing Conflicts
# Keep feature branches short-lived
# Pull from main frequently
git switch feature-branch
git fetch origin
git rebase origin/main
# Communicate about overlapping work
# Use feature flags for incomplete features
Resolving Team Conflicts
When conflicts occur:
# 1. Fetch latest changes
git fetch origin
# 2. Rebase your branch
git rebase origin/main
# 3. Resolve conflicts collaboratively
# - Talk to other developers
# - Understand both changes
# - Test combined result
# 4. Push resolved changes
git push --force-with-lease origin feature-branch
Release Management
Semantic Versioning
Version format: MAJOR.MINOR.PATCH
MAJOR: Breaking changes (v1.0.0 β v2.0.0)
MINOR: New features, backward compatible (v1.0.0 β v1.1.0)
PATCH: Bug fixes, backward compatible (v1.0.0 β v1.0.1)
Examples:
v1.0.0 β Initial release
v1.0.1 β Bug fix
v1.1.0 β New feature added
v2.0.0 β Breaking API changes
Release Workflow
# 1. Create release branch
git switch -c release/v1.2.0 develop
# 2. Update version numbers
echo "1.2.0" > VERSION
git commit -m "Bump version to 1.2.0"
# 3. Generate changelog
git log --oneline v1.1.0..HEAD > CHANGELOG-1.2.0.md
# 4. Final testing and bug fixes
git commit -m "Fix release blocker bug"
# 5. Merge to main and tag
git switch main
git merge --no-ff release/v1.2.0
git tag -a v1.2.0 -m "Release version 1.2.0"
# 6. Deploy to production
git push origin main --tags
# 7. Merge back to develop
git switch develop
git merge --no-ff release/v1.2.0
Team Communication
Commit Message Conventions
Conventional Commits format:
type(scope): description
[optional body]
[optional footer]
Examples:
feat(auth): add login endpoint
fix(ui): resolve button alignment issue
docs(api): update authentication guide
refactor(db): optimize user queries
test(auth): add integration tests
Branch Naming Conventions
feature/JIRA-123-user-authentication
bugfix/issue-456-login-error
hotfix/security-patch-cve-2023-001
release/v1.2.0
experiment/new-ui-framework
Automation and Tooling
Git Hooks for Teams
Pre-commit hook:
#!/bin/sh
# .git/hooks/pre-commit
# Run linting
npm run lint
if [ $? -ne 0 ]; then
echo "Lint failed. Commit aborted."
exit 1
fi
# Run tests
npm test
if [ $? -ne 0 ]; then
echo "Tests failed. Commit aborted."
exit 1
fi
CI/CD Integration
GitHub Actions workflow:
# .github/workflows/ci.yml
name: CI
on:
pull_request:
branches: [ main, develop ]
push:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- run: npm ci
- run: npm test
- run: npm run lint
Troubleshooting Team Issues
Common Collaboration Problems
Problem: Force push conflicts
# Solution: Use --force-with-lease
git push --force-with-lease origin feature-branch
# Recovery for affected team members:
git fetch origin
git reset --hard origin/feature-branch
Problem: Large binary files
# Solution: Use Git LFS
git lfs track "*.psd"
git lfs track "*.zip"
git add .gitattributes
git commit -m "Track large files with LFS"
Summary
You now understand Git collaboration workflows:
- β GitHub Flow for continuous deployment teams
- β GitFlow for structured release cycles
- β Pull request best practices and review processes
- β Conflict resolution and prevention strategies
- β Release management with semantic versioning
- β Team communication conventions
- β Automation and tooling integration
Next Steps
Now that you understand collaboration, let's explore Git configuration and customization:
Practice Tip: Try different workflows with your team to find what works best for your project size, release schedule, and team dynamics.