Lesson 13: Collaborating with Others

What You'll Learn

In this lesson, you'll learn how to collaborate with other developers using Git and GitHub. You'll understand forking, cloning, and contributing to projects.

Types of Collaboration

Scenario Approach
Team project (you have write access) Clone and push directly
Open source (no write access) Fork, then pull request
Reading someone's code Clone (no push)

Part 1: Cloning Repositories

What is Cloning?

Cloning creates a complete copy of a repository on your computer, including all history.

Clone via HTTPS

git clone https://github.com/username/project.git

Clone via SSH

git clone git@github.com:username/project.git

Clone to Specific Folder

git clone git@github.com:username/project.git my-folder

What Cloning Does

  • Downloads all files
  • Downloads all history
  • Sets up origin remote automatically
  • Creates a working directory

Part 2: Forking Repositories

What is Forking?

Forking creates a copy of a repository in YOUR GitHub account. Use this for open source contribution.

Fork Workflow

  1. Go to the repository on GitHub
  2. Click Fork button (top right)
  3. GitHub creates a copy in your account
  4. Clone YOUR fork to your computer
  5. Make changes and push to your fork
  6. Create Pull Request to original repo

Fork vs Clone:

  • Fork: Copy on GitHub (in your account)
  • Clone: Copy on your computer

Part 3: Working with Forks

Clone Your Fork

# Clone your fork
git clone git@github.com:YOUR_USERNAME/project.git
cd project

Add Upstream Remote

Link to the original repository to get updates:

# Add original repo as "upstream"
git remote add upstream git@github.com:ORIGINAL_OWNER/project.git

# Verify remotes
git remote -v

You should see:

origin     git@github.com:YOUR_USERNAME/project.git (fetch/push)
upstream   git@github.com:ORIGINAL_OWNER/project.git (fetch/push)

Keep Your Fork Updated

# Fetch from upstream
git fetch upstream

# Merge into your main
git switch main
git merge upstream/main

# Push to your fork
git push origin main

Part 4: Contributing to Open Source

Complete Contribution Workflow

  1. Fork the repository on GitHub
  2. Clone your fork locally
  3. Create a branch for your changes
  4. Make changes and commit
  5. Push to your fork
  6. Create Pull Request to original repo
  7. Respond to review comments
  8. Wait for merge!
# 1-2. Fork on GitHub, then clone
git clone git@github.com:YOUR_USERNAME/project.git
cd project

# 3. Create branch
git switch -c fix/typo-in-readme

# 4. Make changes
echo "Fixed typo" >> README.md
git add README.md
git commit -m "Fix typo in README"

# 5. Push to your fork
git push -u origin fix/typo-in-readme

# 6. Go to GitHub and create Pull Request

Part 5: Team Collaboration

With Write Access

If you're a team member with write access:

  1. Clone the repository directly
  2. Create feature branches
  3. Push branches to origin
  4. Create Pull Requests for review
  5. Merge after approval

Best Practices

  • Pull before starting work
  • Create feature branches (don't work on main)
  • Keep commits small and focused
  • Write clear commit messages
  • Request reviews before merging

Part 6: Handling Multiple Remotes

Remote What It Is
origin Your fork or main repo
upstream Original repo (for forks)
teammate Teammate's fork (optional)

Add Additional Remote

git remote add teammate git@github.com:teammate/project.git

Fetch from Specific Remote

git fetch upstream
git fetch teammate

Push to Specific Remote

git push origin main
git push upstream main

Part 7: Code Review Best Practices

As a Contributor

  • Test your changes before submitting
  • Follow project guidelines (CONTRIBUTING.md)
  • Write clear PR descriptions
  • Respond promptly to review comments
  • Be patient - maintainers are often volunteers

As a Reviewer

  • Be respectful and constructive
  • Explain why you suggest changes
  • Acknowledge good work
  • Test the changes if possible
  • Respond in reasonable time

Practice Exercise

  1. Find a public repository on GitHub (or use a friend's)
  2. Fork it to your account
  3. Clone your fork locally
  4. Add the original as upstream remote
  5. Create a branch
  6. Make a small change (like fixing a typo in README)
  7. Commit and push to your fork
  8. Create a Pull Request (or practice the workflow)

Summary

Collaboration Workflow

Step Command
Clone repository git clone <url>
Add upstream git remote add upstream <url>
Sync from upstream git fetch upstream
Merge upstream changes git merge upstream/main

Remember: Fork → Clone → Branch → Change → Push → Pull Request

What's Next?

In the final lesson, you'll learn GitHub best practices, workflows, and tips for professional development. You'll wrap up everything you've learned!