Master Git in 30 Days

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

  1. Merge conflicts: Multiple people editing the same files
  2. Diverging branches: Local and remote getting out of sync
  3. Lost commits: Accidentally overwriting others’ work
  4. 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

  1. Descriptive title: “Add user authentication feature”
  2. Detailed description:
    • What does this PR do?
    • Why is this change needed?
    • How was it tested?
  3. Keep it small: Easier to review
  4. One concern per PR: Don’t mix features and fixes
  5. Update with main: Ensure it merges cleanly

Reviewing Pull Requests

  1. Check the code logic and style
  2. Test locally if possible
  3. Leave constructive feedback
  4. Approve or request changes
  5. 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:

  1. Require pull request reviews
  2. Require status checks (CI/CD)
  3. Enforce linear history
  4. 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

  1. Pull before push: Always get latest changes first
  2. Commit often: Small, logical commits
  3. Push regularly: Share your work, get feedback
  4. Use branches: Keep main stable
  5. Write tests: Catch issues before others do
  6. Review code: Learn from each other
  7. Communicate: Over-communicate if needed
  8. Document: README, wiki, comments
  9. Be patient: Conflicts happen, work through them
  10. 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