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
originremote 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
- Go to the repository on GitHub
- Click Fork button (top right)
- GitHub creates a copy in your account
- Clone YOUR fork to your computer
- Make changes and push to your fork
- 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
- Fork the repository on GitHub
- Clone your fork locally
- Create a branch for your changes
- Make changes and commit
- Push to your fork
- Create Pull Request to original repo
- Respond to review comments
- 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:
- Clone the repository directly
- Create feature branches
- Push branches to origin
- Create Pull Requests for review
- 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
- Find a public repository on GitHub (or use a friend's)
- Fork it to your account
- Clone your fork locally
- Add the original as upstream remote
- Create a branch
- Make a small change (like fixing a typo in README)
- Commit and push to your fork
- 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!