Day 26: Multiple People Working in the Same Remote Repository
When multiple people work in the same repository, coordination and understanding of Git workflows become crucial. This article explores best practices and common scenarios for team collaboration.
Common Challenges in Team Collaboration
- Merge conflicts: Multiple people editing the same files
- Diverging branches: Local and remote getting out of sync
- Lost commits: Accidentally overwriting others’ work
- Communication gaps: Not knowing what others are working on
Basic Team Workflow
Daily Workflow
# Morning: Get latest changes
git pull origin main
# Create feature branch
git checkout -b feature-name
# Work and commit frequently
git add .
git commit -m "Progress on feature"
# Before finishing: update with latest main
git checkout main
git pull origin main
git checkout feature-name
git merge main
# Resolve any conflicts
# Push your branch
git push origin feature-name
# Create pull request for review
Staying Updated
Fetch changes regularly:
# Check what's changed
git fetch origin
# View remote changes
git log main..origin/main
# Merge if appropriate
git merge origin/main
Handling Concurrent Work
Scenario 1: Same Files, Different Lines
Usually merges automatically:
git pull origin main
# If auto-merge succeeds, you're done!
Scenario 2: Same Files, Same Lines
Requires manual resolution:
git pull origin main
# Conflict!
# Edit conflicting files
# Remove markers: <<<<<<<, =======, >>>>>>>
# Keep the correct changes
# Stage resolved files
git add resolved-file.txt
# Complete the merge
git commit
Scenario 3: One Person Rebases
Can cause major issues if branch is shared:
# If someone rebased a shared branch
git fetch origin
# You need to rebase your work
git rebase origin/feature-branch
# Or start fresh
git reset --hard origin/feature-branch
Code Review Process
Creating Good Pull Requests
- Descriptive title: “Add user authentication feature”
- Detailed description:
- What does this PR do?
- Why is this change needed?
- How was it tested?
- Keep it small: Easier to review
- One concern per PR: Don’t mix features and fixes
- Update with main: Ensure it merges cleanly
Reviewing Pull Requests
- Check the code logic and style
- Test locally if possible
- Leave constructive feedback
- Approve or request changes
- Merge when ready
Resolving Team Conflicts
Communication First
- Talk to your team: Often prevents issues
- Use PR comments: Ask questions, discuss approaches
- Document decisions: Update PR description or comments
Technical Solutions
Resolve Conflicts
# Update your branch
git fetch origin
git merge origin/main
# Resolve conflicts in files
# Stage changes
git add .
# Complete merge
git commit
Abort and Start Over
# If resolution is too complex
git merge --abort
# Talk to the other developer
# Coordinate who makes what changes
Branch Protection Rules
On GitHub, protect important branches:
- Require pull request reviews
- Require status checks (CI/CD)
- Enforce linear history
- Include administrators
Configure in: Settings > Branches > Branch protection rules
Continuous Integration
Use CI to catch issues early:
# Example .github/workflows/test.yml
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npm test
Communication Tools
Commit Messages
Follow conventions:
<type>(<scope>): <subject>
<body>
<footer>
Example:
feat(auth): add user login functionality
Implement JWT-based authentication with email and password.
Includes password hashing with bcrypt and token refresh.
Closes #123
Pull Request Templates
Create .github/pull_request_template.md:
## Description
<!-- Describe your changes -->
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
## Testing
<!-- How was this tested? -->
## Checklist
- [ ] Tests pass
- [ ] Documentation updated
- [ ] No merge conflicts
Handling Large Teams
Feature Flags
Deploy code that’s not ready yet:
if (featureFlags.newUI) {
return <NewUI />;
} else {
return <OldUI />;
}
Release Branches
Separate development from releases:
main (production)
├── release/v2.0
├── release/v1.9
└── develop (integration)
├── feature/login
├── feature/dashboard
└── feature/reports
Best Practices Summary
- Pull before push: Always get latest changes first
- Commit often: Small, logical commits
- Push regularly: Share your work, get feedback
- Use branches: Keep main stable
- Write tests: Catch issues before others do
- Review code: Learn from each other
- Communicate: Over-communicate if needed
- Document: README, wiki, comments
- Be patient: Conflicts happen, work through them
- Help others: Team success is your success
Today’s Summary
Successful team collaboration with Git requires both technical skills and good communication. Understanding common workflows, handling conflicts gracefully, and using tools like pull requests and CI/CD will help your team work smoothly together.
Let me reorganize the Git commands and parameters learned today:
- git pull origin main
- git fetch origin
- git merge origin/main
- git rebase origin/branch
- git push origin branch
- git log main..origin/main
- Back to Table of Contents
- Previous Day: Using GitHub Remote Repository - Concepts
- Next Day: Version Control Through Branches in the Same Remote Repository