Essential Git workflows and best practices for teams.
Essential Git Workflows for Development Teams
Git is the universal language of modern software development. Understanding Git deeply enables smooth collaboration, safe experimentation, and reliable delivery.
Beyond Basic Commands
If you know commit, push, and pull, you're scratching the surface. Let's explore workflows that make teams effective.
Branching Strategies
Git Flow
Classic model for release-based development:
- main: production code only
- develop: integration branch
- feature/*: individual features
- release/*: release preparation
- hotfix/*: emergency production fixes
GitHub Flow
Simpler model for continuous deployment:
- main is always deployable
- Feature branches off main
- Pull request for review
- Merge directly to main
- Deploy immediately
Trunk-Based Development
Minimal branching for high-velocity teams:
- Short-lived feature branches (1-2 days)
- Feature flags for incomplete features
- Direct commits to main acceptable for small changes
- Continuous integration essential
Commit Best Practices
Atomic Commits
Each commit should:
- Make one logical change
- Be independently reviewable
- Pass all tests
- Have clear purpose
Commit Messages
Write helpful messages:
- First line: imperative mood, under 50 characters
- Blank line separating summary from body
- Body explains what and why, not how
- Reference issues or tickets
Example:
Add email validation to signup form
Prevents users from submitting malformed email addresses
which was causing delivery failures and support tickets.
Fixes #234
The Power of Rebase
Understanding Rebase
Rebase moves commits to a new base:
- Creates cleaner history than merge
- Makes feature branches appear as if just created
- Enables interactive history editing
Interactive Rebase
Rewrite history before sharing:
- Squash related commits together
- Reword commit messages
- Reorder commits logically
- Drop experimental commits
When to Rebase
- Before creating a pull request
- To incorporate main branch changes
- To clean up messy history
When NOT to Rebase
- Shared branches others have pulled
- main or develop branches
- After pushing (without force)
Handling Merge Conflicts
Prevention
- Keep branches short-lived
- Communicate about shared files
- Pull/rebase frequently
- Modular code reduces conflicts
Resolution
- Understand both changes first
- Don't blindly accept one side
- Test thoroughly after resolving
- Ask original authors if unclear
Tools
- Configure visual merge tools
- Use IDE integration
- git mergetool command
Useful Git Commands
Stashing
Save work without committing:
- git stash: save current changes
- git stash pop: apply and remove
- git stash list: see all stashes
- git stash drop: discard a stash
Cherry-Picking
Apply specific commits:
- git cherry-pick <commit>: apply one commit
- Useful for hotfixes
- Maintains commit history
Bisect
Find which commit introduced a bug:
- git bisect start
- Mark good and bad commits
- Git finds the problematic commit
Reflog
Recover from mistakes:
- git reflog: show all HEAD history
- Recover "lost" commits
- Undo accidental deletions
Code Review with Pull Requests
Creating Good PRs
- Descriptive title and description
- Reference related issues
- Keep changes focused
- Include testing instructions
- Add screenshots for UI changes
Reviewing Effectively
- Understand context before reviewing
- Test the changes locally
- Comment constructively
- Approve only when ready
Responding to Reviews
- Address all comments
- Don't take feedback personally
- Explain decisions when disagreeing
- Update PR based on feedback
CI/CD Integration
Automated Checks
Configure pipelines to:
- Run tests on every push
- Check code formatting
- Run linters
- Verify build succeeds
- Check for security issues
Protected Branches
Enforce quality:
- Require passing CI
- Require code review
- Prevent force pushes
- Require linear history
Managing Large Repositories
Git LFS
For large files:
- Track binary files without bloating repo
- Separate storage for large assets
- Configure tracked file types
Submodules
For composite projects:
- Reference other repositories
- Pin to specific commits
- Separate versioning
Troubleshooting
Common Issues
- Detached HEAD: checkout a branch
- Merge conflicts: resolve and commit
- Pushed wrong commit: revert, don't force push
- Lost commits: check reflog
When Things Go Wrong
- Don't panic
- Check reflog before assuming data is lost
- Ask for help before force pushing
- Most problems are recoverable
Building Git Fluency
Git mastery comes from:
- Daily practice
- Understanding the data model
- Learning from mistakes
- Reading documentation
- Helping teammates
The best Git users rarely need to consult documentation because they understand how Git thinks. Invest in learning Git deeply—it's a skill you'll use every day for years.