Lesson

GitHub Fork

10 min reading
Free Course

GitHub Fork: Contributing Safely to Repositories You Don't Own

A fork is an independent copy of someone else's GitHub repository created under your own GitHub account. Forking lets you experiment, commit fixes, and open pull requests to open-source or team projects where you do not have direct write permission.

Fork vs Clone: Understanding the Difference

New contributors often confuse forking and cloning because both copy code:

  • Forking happens on GitHub's servers, creating github.com/your-username/project linked to the original repository.
  • Cloning downloads a repository (usually your fork) onto your laptop so you can edit files and run tests locally.

Cloning Your Fork and Linking upstream

After clicking Fork on the target repository on GitHub, clone your own fork locally and add the original repository as a second remote named upstream:

git clone git@github.com:your-username/starter-site.git
cd starter-site
git remote add upstream git@github.com:original-org/starter-site.git
git remote -v

Now origin points to your writable fork on GitHub, while upstream points to the original project so you can pull fresh maintainer updates.

Keeping Your Fork Synced with upstream

Before starting a new contribution branch, pull the latest commits from upstream/main into your local main and push them up to your fork:

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

GitHub also offers a convenient Sync fork button on your fork's main page if you want to fast-forward main in the browser before pulling locally.

Common Forking Mistakes

Committing your bug fix directly onto your fork's main branch makes syncing future updates messy and prevents submitting two separate pull requests cleanly. Always branch off main (git switch -c fix/header-spacing) inside your fork for each PR.

Frequently Asked Questions

Can I fork a private repository?

Yes, if the repository owner or organization enables forking for collaborators. Forks of private repositories remain private and inherit collaborator visibility rules.

Does deleting my fork affect the original repository?

No. Your fork is completely independent, though deleting it closes any open pull requests you submitted from that fork.

What happens if the original repository gets new commits while I work on my fork?

Your fork does not auto-sync. Run git fetch upstream and merge or rebase upstream/main into your feature branch to stay current.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol
Git Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum