Git & GitHub Course
Git & GitHub
/
Intermediate

Forking Repositories

Definition

A fork is a complete, personal copy of someone else's repository that lives on your account. Forks allow you to freely make changes to a project without affecting the original upstream repository.

Explain Like I'm New

The 'Copy and Paste' button of Open Source. If you want to fix a bug in the React framework, Facebook will not give you permission to edit their files. Instead, you click 'Fork'. GitHub instantly creates a perfect clone of React on YOUR profile. You fix the bug on your copy, and then politely ask Facebook to copy your fix over to theirs (a Pull Request).

Real World Example

Creating your own custom version of an open-source video game emulator, adding your own features, and releasing it as a totally independent project.

Common Use Cases

  • •Open Source contributing
  • •Creating independent spin-off projects

Terminal Output

bash / terminal
/* The Standard Open Source Workflow: 1. Click 'Fork' on the target GitHub repository. (This copies it from facebook/react to your-name/react) 2. Clone YOUR fork to your computer: $ git clone https://github.com/your-name/react.git 3. Make a branch, fix the bug, commit, and push: $ git push origin bug-fix 4. Go to GitHub and click 'Create Pull Request' to send the code back to the original author! */

Interview Questions

basic

  • Is 'forking' a native Git command?

intermediate

  • If the original repository updates, does your fork update automatically?

Flash Cards

Question

Is it native Git?

Click to reveal answer
Answer

No! `git fork` does not exist. Forking is a feature explicitly invented by GitHub/GitLab to manage permissions in the cloud.

Question

Updates automatically?

Click to reveal answer
Answer

No. Once you fork a repository, your copy is isolated. If the original author adds new code, you have to manually 'Sync Fork' in the GitHub UI to pull their new changes into your copy.