Git Workflow Best Practices for Teams
Learn effective Git workflows and collaboration strategies that help teams ship code faster and with fewer conflicts.
Git Workflow Best Practices for Teams
Effective version control is the foundation of successful team collaboration. Let's explore Git workflows and practices that help teams work together seamlessly.
Choosing a Workflow
GitHub Flow (Recommended for Most Teams)
Simple and effective for continuous deployment:
main ──●────●────●────●────●────●───►
\ / \ /
feature ●────● ●────●
- Create a branch from
main - Make commits
- Open a pull request
- Review and discuss
- Merge to
main - Deploy
GitFlow (For Release-Based Projects)
More complex, suitable for versioned releases:
main ────●────────────●────────►
\ /
release ●────●───●
/
develop ●───●───●───●───●───●───►
\ /
feature ●─●
Branch Naming Conventions
Consistent naming helps everyone understand what's happening:
# Feature branches
feature/user-authentication
feature/add-shopping-cart
# Bug fixes
fix/login-redirect-issue
fix/memory-leak-dashboard
# Releases
release/v2.1.0
# Hotfixes
hotfix/security-patch
Commit Message Guidelines
The Conventional Commits Format
<type>(<scope>): <description>
[optional body]
[optional footer]
Examples
# Good commit messages
feat(auth): add OAuth2 login support
fix(api): handle null response in user endpoint
docs(readme): update installation instructions
refactor(utils): simplify date formatting logic
# Bad commit messages
fixed stuff
WIP
asdfasdf
update code
Types
- feat: New feature
- fix: Bug fix
- docs: Documentation changes
- style: Formatting, missing semicolons, etc.
- refactor: Code refactoring
- test: Adding or updating tests
- chore: Maintenance tasks
Pull Request Best Practices
Writing Good PR Descriptions
## What does this PR do?
Adds user authentication using OAuth2 with Google provider.
## Why is this needed?
Users requested social login to simplify the signup process.
## How to test
1. Click "Sign in with Google"
2. Complete OAuth flow
3. Verify user is logged in
## Screenshots
[Include if UI changes]
## Checklist
- [ ] Tests added/updated
- [ ] Documentation updated
- [ ] No console errors
Code Review Etiquette
For Reviewers:
- Be constructive and specific
- Ask questions instead of making demands
- Approve when good enough, not perfect
- Respond promptly
For Authors:
- Keep PRs small and focused
- Respond to feedback professionally
- Don't take criticism personally
Handling Merge Conflicts
Prevention
# Keep your branch updated
git fetch origin
git rebase origin/main
# Or merge main into your branch
git merge origin/main
Resolution
# When conflicts occur during rebase
git status # See conflicted files
# Edit files to resolve conflicts
# Remove conflict markers: <<<<<<<, =======, >>>>>>>
git add <resolved-files>
git rebase --continue
# If things go wrong
git rebase --abort
Useful Git Commands
Interactive Rebase
Clean up commits before merging:
# Squash last 3 commits
git rebase -i HEAD~3
# In the editor:
pick abc123 First commit
squash def456 Second commit
squash ghi789 Third commit
Stashing
Save work temporarily:
# Stash current changes
git stash
# Stash with a name
git stash save "work in progress on feature X"
# List stashes
git stash list
# Apply and remove
git stash pop
# Apply without removing
git stash apply stash@{0}
Cherry-Pick
Apply specific commits:
# Apply a commit from another branch
git cherry-pick abc123
# Cherry-pick without committing
git cherry-pick -n abc123
Git Hooks
Automate checks before commits:
# .husky/pre-commit
npm run lint
npm run test
Setting Up with Husky
npm install husky --save-dev
npx husky install
npx husky add .husky/pre-commit "npm run lint"
Common Mistakes to Avoid
1. Committing Sensitive Data
# If you accidentally commit secrets
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch path/to/secret' \
--prune-empty --tag-name-filter cat -- --all
# Better: Use .gitignore and environment variables
2. Force Pushing to Shared Branches
# ❌ Never do this on main/develop
git push --force origin main
# ✅ Use force-with-lease (safer)
git push --force-with-lease origin feature-branch
3. Huge Commits
Break large changes into logical commits:
# Stage specific parts of files
git add -p
# Review what you're committing
git diff --staged
Team Configuration
Recommended .gitconfig
[alias]
co = checkout
br = branch
ci = commit
st = status
lg = log --oneline --graph --decorate
[pull]
rebase = true
[merge]
conflictStyle = diff3
[core]
autocrlf = input # Use 'true' on Windows
Conclusion
Good Git practices make collaboration smoother and deployments safer. The key is consistency—pick a workflow, establish conventions, and stick to them. Your future self (and your teammates) will thank you!