Collaborating with Teams
Duration: 8 min
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
- Go to your repository on GitHub
- Click "Settings" → "Collaborators"
- Click "Add people"
- Enter their GitHub username
- 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 -vorigin 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/mainWorkflow for Team Collaboration
- Pull latest changes from main
- Create a feature branch
- Make changes and commit
- Push to GitHub
- Create a Pull Request
- Review and get approval
- 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 GitHubHandling Merge Conflicts
When two people edit the same file, Git can't automatically merge. You'll see:
CONFLICT (content conflict): Merge conflict in model.pyResolving 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-nameCommunication 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/branchScenario 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-leaseScenario 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-leaseinstead of--forcefor safety.
❓ What should you do before starting work on a feature?