Skip to content

How to fork a repository

This guide explains how to fork a repository on GitHub, step-by-step, and clarifies how forking differs from copying a repository.

A fork is a server-side copy of a repository in your own GitHub account. It preserves the commit history and connection to the original (upstream) repository so you can make changes, open pull requests, and keep your fork in sync with upstream updates.

  • Fork when you plan to contribute back to the original project, want an independent workspace in your GitHub account, or need to create a visible public copy with a relationship to the upstream project.
  • Copy (download/archive or clone and push to a new repo) when you want a fresh, unrelated starting point or a private copy without any connection to the original project.

Step-by-step: Forking a repository on GitHub (web)

Section titled “Step-by-step: Forking a repository on GitHub (web)”
  1. Open the repository page on GitHub (e.g., https://github.com/owner/repo or https://github.com/BankyNarayan/Test).

  2. Click the “Fork” button in the top-right of the repository page.

  3. Choose your account or organization where you want the fork to live.

  4. GitHub creates the fork under your account: https://github.com/your-username/repo

  5. Clone your fork locally:

    git clone https://github.com/your-username/repo.git

  6. Add the upstream remote so you can pull future updates from the original repo:

    cd repo git remote add upstream https://github.com/owner/repo.git

  7. Work on a feature branch and commit changes:

    git checkout -b feature/my-change git add . git commit -m “Describe change”

  8. Push your branch to your fork:

    git push origin feature/my-change

  9. Create a Pull Request (PR) from your fork/branch back to the original repository via GitHub web UI.

  10. Keep your fork up-to-date with upstream (example using main/master):

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

  1. Authenticate the CLI if not already:

    gh auth login

  2. Fork the repo:

    gh repo fork owner/repo —clone=false —remote=true

  3. Clone your fork (if you didn’t use —clone):

    gh repo clone your-username/repo

  4. The gh repo fork command can automatically add an upstream remote and set the origin to your fork depending on flags.

How a fork differs from copying a repository

Section titled “How a fork differs from copying a repository”
  • Relationship: A fork maintains metadata linking it to the upstream repository; a simple copy does not.
  • Contribution workflow: Forks are intended to submit pull requests back to upstream. Copies are typically used when you want an unrelated starting point.
  • Visibility & discoverability: Forks show up in the network graph and indicate how many forks a project has.
  • Syncing: Forks can be kept in sync with upstream; copied repositories require manual synchronization.
  • Create a branch per feature/PR.
  • Rebase or merge upstream changes before opening a PR to reduce conflicts.
  • Use gh CLI for convenience when creating PRs and keeping remotes configured.

This page explains forking on GitHub and why it’s different from copying; adapt instructions to your workflow (SSH vs HTTPS, branch names, protected branches).