LinuxCommandLibrary

git-fork

Create a remote, server-side repository fork

TLDR

Fork and clone a GitHub repository by its URL

$ git fork [https://github.com/tldr-pages/tldr]
copy

Fork and clone a GitHub repository by its slug
$ git fork [tldr-pages/tldr]
copy

SYNOPSIS

git-fork <repository> [options]
(Non-standard; use gh repo fork <repo> instead)

DESCRIPTION

The git-fork command does not exist as a native part of Git. Git itself lacks a built-in fork subcommand because forking is primarily a feature of hosted platforms like GitHub, GitLab, or Bitbucket. These services allow users to create a personal copy (fork) of a repository to contribute changes without affecting the original.

On the Linux command line, simulate forking with a workflow using core Git commands: clone the target repository, create a mirror or bare clone if needed, push to your own remote repository on the hosting service. For example:
- Create a repository on GitHub via web or CLI.
- git clone <upstream>
- git remote add origin <your-repo>
- git push -u origin main

Modern GitHub CLI (gh) provides gh repo fork as the closest native equivalent, automating the web-based fork and setting up remotes.

This absence in core Git emphasizes its distributed nature—every clone is a full fork. Third-party tools or scripts sometimes named 'git-fork' may exist in specific projects but are not portable or standard. Use platform-specific CLIs for streamlined forking in workflows like open-source contributions.

CAVEATS

No official git-fork command exists in Git (>=2.46). Relying on non-standard tools risks incompatibility. Always verify hosting service permissions before simulating forks.

MANUAL FORK WORKFLOW

1. Create empty repo on hosting service.
2. git clone https://github.com/user/repo.git
3. cd repo
4. git remote add fork https://github.com/yourusername/repo.git
5. git push -u fork main
Track upstream: git remote add upstream https://github.com/user/repo.git

PLATFORM ALTERNATIVES

GitHub: gh repo fork REPO
GitLab: glab repo fork
Use browser for one-click forks.

HISTORY

Forking popularized by GitHub in 2008; Git core team never added native support, favoring distributed clones. GitHub CLI introduced gh repo fork in 2020 for CLI parity.

SEE ALSO

git clone(1), git remote(1), gh repo fork(1), hub fork(1)

Copied to clipboard