1

I am trying to figuring out how do I fork a git/github repository using command line.

I tried but it says 'fork' is not a git command.. Is there any way to fork a repository using commmand line.

git: 'fork' is not a git command.
See 'git --help'.

The most similar command is fsck
Sajjad Ali
  • 91
  • 2
  • 10
  • `fork` is not a command. To make a new branch, use `git branch`. To create a new repo, use `git clone`. To make a fork, use `git clone` to make a new repo, and then call the new repo a fork. – William Pursell Jan 05 '21 at 14:15

2 Answers2

6

A Fork is a GitHub operation, not a Git one.

You can use the GitHub CLI gh fork command to make a fork.

Example:

# Create a fork for another repository.
~/Projects$ gh repo fork cli/cli
- Forking cli/cli...
✓ Created fork cli/cli
? Would you like to clone the fork? Yes
Cloning into 'cli'...
✓ Cloned fork
~/Projects$ cd cli
~/Projects/cli$

That way, you don't have to clone any repository: the forked repository is created and then cloned for you.

This is different from creating a branch inside your own repository.


See also gh repo fork -- fork-name=xxx with gh 2.5.0 (Feb. 2022)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • do we fork any **git** repository using github cli ??? or only github repositories??? – Sajjad Ali Jun 13 '23 at 03:15
  • 1
    @SajjadAli A [fork](https://stackoverflow.com/a/6286877/6309) is not a Git feature, but one provided by the remote Git repositories hosting service. Here, it is for GitHub repositories only, using their `gh` CLI: that fits the "github" tag under this question. For GitLab, you would use their own CLI `glab`, with [`glab repo fork [flags]`](https://gitlab.com/gitlab-org/cli/-/blob/main/docs/source/repo/fork.md) – VonC Jun 13 '23 at 05:09
1

Use hub command line tool that was specifically designed to work with Github. Install it or download it and add it to your PATH and then do:

alias git=hub

You can now do git fork to fork the repository you're currently in. hub also comes with other useful commands, for example you can do git pull-request to send a pull request in the command line (do not confuse it with git-request-pull which is the built-in Git command)

Arkadiusz Drabczyk
  • 11,227
  • 2
  • 25
  • 38