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.
- 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:
git clone https://github.com/username/project.gitIf you started a folder locally with git init first, link it to a new empty GitHub repo and push your main branch:
git remote add origin https://github.com/username/project.git
git push -u origin mainThat -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 fetchquietly 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 pullis 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:
git switch main
git pull origin main
git switch -c feat/add-footer-linksOpening a Clean Pull Request (PR)
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."
- Push your feature branch to GitHub:
git push -u origin feat/add-footer-links - Open the repository on GitHub and click Compare & pull request (or run
gh pr create --fillif you have the official GitHub CLI installed). - Write a clear summary explaining what changed, why, and how you verified it (tests/screenshots).
- 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! - After the PR merges, pull the updated
mainlocally and delete your old branch:bashgit switch main git pull origin main git branch -d feat/add-footer-links
- 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
You opened a Pull Request on GitHub and a teammate requests a small fix. What should you do?