Script Valley
Git and GitHub Complete Course: From Beginner to Advanced
Working with GitHub: Remotes, Push, Pull, and CollaborationLesson 3.3

Forking and Contributing to Open Source

fork, upstream remote, open source contribution, git clone fork, sync fork, contribution workflow

Forking and Contributing to Open Source

Forking is the process of creating your own copy of someone else's repository under your GitHub account. This is the standard way to contribute to open-source projects where you do not have write access to the original repository.

The Fork and Clone Workflow

On GitHub, click Fork on the target repository. This creates a copy in your account. Then clone your fork locally:

git clone https://github.com/your-username/project-name.git
cd project-name

Adding the Upstream Remote

Add the original repository as a remote called upstream:

git remote add upstream https://github.com/original-owner/project-name.git

Now you have two remotes: origin (your fork) and upstream (the original). You push to origin but pull new changes from upstream.

Syncing Your Fork

Periodically sync your fork with the upstream to stay up to date:

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

The Contribution Workflow

Create a feature branch from main, make your changes, push to your fork, and then open a pull request from your fork's branch to the upstream repository's main branch. The project maintainers will review and merge your contribution.

Up next

Pull Requests and Code Review

Sign in to track progress