Script Valley
Open Source Contribution: A Practical Guide
Git Workflow for ContributorsLesson 2.1

How to fork and clone an open source repository correctly

GitHub fork button, git clone, upstream remote, origin remote, remote tracking, keeping fork in sync, shallow clone

Fork vs Clone

A fork is a server-side copy of a repository under your GitHub account. A clone is a local copy on your machine. You need both to contribute to a project you do not have write access to.

The Setup

# 1. Fork via GitHub UI, then clone YOUR fork
git clone https://github.com/YOUR_USERNAME/PROJECT.git
cd PROJECT

# 2. Add the original repo as upstream
git remote add upstream https://github.com/ORIGINAL_OWNER/PROJECT.git

# 3. Verify remotes
git remote -v
# origin    https://github.com/YOUR_USERNAME/PROJECT.git
# upstream  https://github.com/ORIGINAL_OWNER/PROJECT.git

Keeping Your Fork Synced

Your fork immediately goes stale after you create it. Before starting any new work, sync with upstream:

git fetch upstream
git checkout main
git merge upstream/main
git push origin main

This workflow ensures you always branch off current code. PRs built on stale branches require rebasing -- extra work that frustrates maintainers.

For large repos where you only need recent history, use git clone --depth=1 to fetch a shallow clone. This dramatically reduces download size and time.

Working With Shallow Clones

For repositories with long histories -- some go back 15+ years -- a full clone can take minutes and consume gigabytes. Use git clone --depth=1 to fetch only the latest snapshot. This dramatically reduces download size. When you need history later, deepen selectively: git fetch --deepen=50. Most contribution workflows only need recent history, so shallow clones are practical for the majority of open source work.

Up next

How to create and name branches for pull requests

Sign in to track progress

How to fork and clone an open source repository correctly โ€” Git Workflow for Contributors โ€” Open Source Contribution: A Practical Guide โ€” Script Valley โ€” Script Valley