Fork a Repository Using GitHub CLI

  1. Install GitHub CLI:

  2. Authenticate:

    • Authenticate with your GitHub account using the following command:

      sh

      gh auth login
      
  3. Fork the Repository:

    • Use the gh repo fork command followed by the repository you want to fork. For example, to fork the octocat/Hello-World repository:

      sh

      gh repo fork octocat/Hello-World
      

Example

sh

# Authenticate with GitHub
gh auth login

# Fork the repository
gh repo fork octocat/Hello-World

This will create a fork of the repository in your GitHub account. By default, the CLI will prompt you to choose whether to clone the forked repository to your local machine. You can accept or decline based on your preference.

Additional Options

You can also specify additional options with the gh repo fork command. For example:

  • --clone: Clone the fork after creating it.
  • --remote: Add a remote for the fork.