Module 7 of 13 · Getting Started with AI Development · Beginner

Collaborating with Teams

Duration: 8 min

Try it in Google Colab: Open in Colab

Setting Up Team Collaboration

When working with a team, everyone needs access to the same repository. Here's how to set it up:

Adding Team Members to GitHub

  1. Go to your repository on GitHub
  2. Click "Settings" → "Collaborators"
  3. Click "Add people"
  4. Enter their GitHub username
  5. Choose their permission level (Pull, Triage, Push, Maintain, Admin)

Cloning a Repository

Team members can clone the repository to their local machine:

# Clone the repository
git clone https://github.com/username/my-ai-project.git

# Navigate to the project
cd my-ai-project

# Check the remote
git remote -v
origin  https://github.com/username/my-ai-project.git (fetch)
origin  https://github.com/username/my-ai-project.git (push)

Pulling Latest Changes

Before starting work, always pull the latest changes:

# Update your local repository
git pull origin main

# Or fetch and merge separately
git fetch origin
git merge origin/main

Workflow for Team Collaboration

  1. Pull latest changes from main
  2. Create a feature branch
  3. Make changes and commit
  4. Push to GitHub
  5. Create a Pull Request
  6. Review and get approval
  7. Merge into main
# 1. Pull latest
git pull origin main

# 2. Create feature branch
git checkout -b feature/add-logging

# 3. Make changes
echo 'import logging' >> model.py
git add model.py
git commit -m 'Add logging support'

# 4. Push to GitHub
git push origin feature/add-logging

# 5-7. Create PR, get review, merge on GitHub

Handling Merge Conflicts

When two people edit the same file, Git can't automatically merge. You'll see:

CONFLICT (content conflict): Merge conflict in model.py

Resolving Conflicts

# Open the conflicted file
# You'll see markers like:
# <<<<<<< HEAD
# your changes
# =======
# their changes
# >>>>>>> branch-name

# Edit the file to keep what you want
# Then mark as resolved
git add model.py
git commit -m 'Resolve merge conflict'
git push origin feature/branch-name

Communication Best Practices

Practice Example
Clear commit messages "Add data validation" not "fix"
Descriptive PR titles "Add preprocessing pipeline"
Link related issues "Fixes #42" in PR description
Comment on code Explain why, not just what
Use branches for features Never push directly to main

Common Team Scenarios

Scenario 1: Someone Pushed While You Were Working

# Your push is rejected
git pull origin main
# Resolve any conflicts
git push origin feature/branch

Scenario 2: You Need to Update Your Branch

# Rebase your branch on latest main
git fetch origin
git rebase origin/main
git push origin feature/branch --force-with-lease

Scenario 3: Accidentally Committed to Main

# Create a new branch from current state
git branch feature/oops

# Reset main to previous commit
git reset --hard HEAD~1

# Switch to your feature branch
git checkout feature/oops

💡 Tip: Always communicate with your team before force-pushing. Use --force-with-lease instead of --force for safety.

❓ What should you do before starting work on a feature?

← Previous Continue interactively → Next →

Related Courses