Git Workflow for Teams
What You Will Learn
Git is the foundation for collaboration in software teams. This guide explains branches, commits, pull requests, merge, rebase, tags, and release workflow basics.
Prerequisites
- Git installed locally
- A GitHub, GitLab, or Bitbucket account
- Basic terminal usage
Concept Overview
Git tracks snapshots of your code. Teams use branches to isolate work, commits to save meaningful changes, and pull requests to review before merging.
Step-by-Step Explanation
- Create a feature branch from the latest main branch.
- Make small, related commits.
- Push your branch to the remote repository.
- Open a pull request with a clear summary.
- Address review comments.
- Merge after tests pass.
- Delete the branch after merge.
Use tags for releases and hotfix branches for urgent production fixes.
Code Example
git switch main
git pull --ff-only
git switch -c feature/add-login
git add .
git commit -m "Add login form"
git push -u origin feature/add-login
Real-World Use Cases
- Team collaboration
- Code review
- Release tracking
- CI/CD triggers
- Rollback investigation
Best Practices
- Pull the latest changes before starting work.
- Keep commits focused.
- Write meaningful commit messages.
- Use pull requests for review and discussion.
- Avoid force pushing shared branches.
- Protect main branches with required checks.
Common Mistakes
- Working directly on main
- Committing secrets
- Large unrelated commits
- Resolving merge conflicts without understanding code
- Force pushing over teammate work
Interview Questions
- What is the difference between merge and rebase?
- What is a pull request?
- How do you resolve merge conflicts?
- What is a detached HEAD?
- Why should secrets not be committed?
Summary
A clean Git workflow protects team productivity. Good branches, small commits, and reviewed merges make delivery safer.