A fork is a personal copy of another user's or organization's repository on a Git hosting platform such as GitHub. Forking allows you to work on a project independently without requiring direct write access to the original repository.
A fork is a copy of a repository under your own GitHub account or organization.
Original Repository
↓
Fork
↓
Your GitHub Repository
The fork gives you an independent repository where you can make your own changes.
Forks are commonly used when you want to contribute to a repository without having direct write access to it.
| Fork | Clone |
|---|---|
| Creates a copy on the Git hosting platform | Creates a local copy on your computer |
| Usually performed through GitHub | Performed using the git clone command |
| Creates a repository under your account | Creates a local working repository |
On GitHub, you can open a repository that you want to contribute to and select the Fork option.
GitHub then creates a copy of the repository under your account or an organization where you have permission to create repositories.
The repository from which you create a fork is commonly called the upstream repository in contribution workflows.
Original Repository
↓
Fork
↓
Your Repository
The original repository remains separate from your fork.
Your fork belongs to your GitHub account or selected organization. You can normally create branches and commits in your fork according to its permissions and settings.
github.com/yourname/project
After creating a fork, you can clone your fork to your local computer.
git clone https://github.com/yourname/project.git
Then move into the project directory:
cd project
After cloning your fork, Git normally configures it as the
origin remote.
git remote -v
Example:
origin https://github.com/yourname/project.git (fetch)
origin https://github.com/yourname/project.git (push)
In a fork-based workflow, upstream commonly refers to the original repository from which your fork was created.
upstream → Original Repository
origin → Your Fork
This naming convention helps distinguish your fork from the original project.
After cloning your fork, you can add the original repository as an additional remote:
git remote add upstream https://github.com/original-owner/project.git
Now your local repository can communicate with both
origin and upstream.
Use:
git remote -v
You may see:
origin https://github.com/yourname/project.git (fetch)
origin https://github.com/yourname/project.git (push)
upstream https://github.com/original-owner/project.git (fetch)
upstream https://github.com/original-owner/project.git (push)
To retrieve changes from the original repository:
git fetch upstream
This updates your local remote-tracking information for the
upstream repository.
After fetching upstream changes, you can view its remote-tracking branches:
git branch -r
Example:
origin/main
upstream/main
upstream/develop
It is common to create a separate branch for your contribution.
git switch -c feature-login
This keeps your feature work separate from the default branch.
After creating a feature branch, make the required changes to the project.
git status
git add .
git commit -m "Add login feature"
The commit is created in your local feature branch.
Push your feature branch to your fork:
git push -u origin feature-login
The branch is then available in your fork on the remote hosting platform.
After pushing your changes to your fork, you can create a pull request asking the original repository maintainers to review and potentially merge your changes.
Your Fork
↓
Feature Branch
↓
Pull Request
↓
Original Repository
Fork repository
↓
Clone fork
↓
Add upstream remote
↓
Create feature branch
↓
Make changes
↓
Commit changes
↓
Push branch to fork
↓
Create Pull Request
The original repository may continue to receive changes after you create your fork.
You can retrieve those changes using:
git fetch upstream
You can then integrate the appropriate upstream changes into your local branch according to the project's workflow.
One way to integrate changes from the original repository is:
git switch main
git fetch upstream
git merge upstream/main
This merges the fetched upstream main branch into your local
main branch.
After integrating upstream changes locally, you can update your fork:
git push origin main
This pushes your local main branch to the
origin remote.
A fork can allow you to work on a repository even when you do not have direct write permission to the original repository.
However, access to the original repository and its contribution process is controlled by its owners and settings.
| Fork Workflow | Collaborator Workflow |
|---|---|
| Work from your own copy | Work directly with access to the original repository |
| Common for external contributors | Common for team members with repository access |
| Usually contributes through pull requests | May push branches directly to the repository |
A fork and a branch are different concepts.
git clone FORK_URL
cd project
git remote add upstream ORIGINAL_URL
git fetch upstream
git switch -c feature-name
git add .
git commit -m "Add feature"
git push -u origin feature-name
Use git remote -v to verify your remote configuration.
git remote -v
A typical fork workflow may show:
origin https://github.com/yourname/project.git
upstream https://github.com/original-owner/project.git
Here, origin represents your fork and
upstream represents the original repository.
# Clone your fork
git clone FORK_URL
# Enter project
cd project
# Add original repository
git remote add upstream ORIGINAL_URL
# Get latest upstream information
git fetch upstream
# Create feature branch
git switch -c feature-name
# Make changes
git add .
git commit -m "Add feature"
# Push to your fork
git push -u origin feature-name
origin remote.upstream.Forking creates a separate copy of a repository on a Git hosting platform. It is commonly used in open-source contribution workflows.
Original Repository
↓
Fork
↓
Clone
↓
Feature Branch
↓
Changes
↓
Push
↓
Pull Request
In a typical fork workflow, origin points to your fork
and upstream points to the original repository.
origin normally points to your fork.upstream commonly refers to the original repository.git remote add upstream URL.git fetch upstream to retrieve updates from the original repository.Question: What is a fork in a GitHub workflow?