3. Collaborating on GitHub

GitHub Remotes, Push, Pull & Pull Requests

Connect your local Git repo to GitHub, sync changes with push and pull, understand Fork vs Clone, and open clean Pull Requests for team review.

3 min readUpdated 2026-11-29
In This Lesson
  • Connect local Git repositories to GitHub remotes with push and pull
  • Understand when to Fork vs Clone an open-source project
  • Open and update clean Pull Requests for team code review

Up to now, everything we did in Git lived purely on your own computer. Git is the version-control tool running locally; GitHub is the cloud home where your team backs up code, reviews changes, and ships releases together.

Connecting to a Remote Repository (origin)

A cloud copy of your repository is called a remote, and by convention your main GitHub remote is nicknamed origin.

If you are starting from a project that already exists on GitHub, clone it once to download the full project and its .git history:

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

If you started a folder locally with git init first, link it to a new empty GitHub repo and push your main branch:

bash
git remote add origin https://github.com/username/project.git
git push -u origin main

That -u flag (--set-upstream) links your local main to GitHub's main permanently—so from then on, you only have to type git push or git pull.

git fetch vs git pull: What's the Difference?

  • git fetch quietly downloads metadata about new commits on GitHub so you can inspect them (git log origin/main) without touching any files in your local folder.
  • git pull is a two-in-one shortcut (git fetch + git merge): it downloads new commits from GitHub and immediately merges them into your active branch.

Syncing Before You Start New Work

When collaborating with others, main on GitHub moves forward while you sleep. Always pull the latest changes before creating a new feature branch so you build on fresh code:

bash
git switch main
git pull origin main
git switch -c feat/add-footer-links

Opening a Clean Pull Request (PR)

GitHub Collaboration Flow: Fork → Branch → Pull Request

1. Fork / Clone

origin + upstream

2. Branch & Commit

git switch -c feat/fix

3. Push to origin

git push -u origin

4. Open PR & Merge

Review → CI → Merge

Never push unreviewed work straight to an upstream repository. Work on a branch in your fork (or feature branch) and open a Pull Request.

Instead of pushing straight to main, teams open a Pull Request—a friendly proposal on GitHub saying: "Here is my branch; please review these changes before we merge them into main."

  1. Push your feature branch to GitHub: git push -u origin feat/add-footer-links
  2. Open the repository on GitHub and click Compare & pull request (or run gh pr create --fill if you have the official GitHub CLI installed).
  3. Write a clear summary explaining what changed, why, and how you verified it (tests/screenshots).
  4. If a reviewer asks for a tweak, simply edit the file locally, commit on the same branch, and run git push—GitHub updates your open PR automatically!
  5. After the PR merges, pull the updated main locally and delete your old branch:
    bash
    git switch main
    git pull origin main
    git branch -d feat/add-footer-links
Fork vs Clone: Which Do You Need?
  • Clone (git clone): Downloads a repository directly to your laptop. Use this for your own repos or team repos where you already have write access.
  • Fork: Creates a personal copy of someone else's public repository under your GitHub account. You clone your fork, push your branch to your fork, and open a Pull Request back to the original project.

Quick Checkpoints

Check Your Understanding

You opened a Pull Request on GitHub and a teammate requests a small fix. What should you do?