LinuxCommandLibrary

hub-clone

Clone GitHub repositories using the hub command

TLDR

Clone an existing repository to current directory (If run into authentication problem, try full SSH path)

$ hub clone [remote_repository_location]
copy

SYNOPSIS


`hub clone [] []`

Examples:
Clone a repository from a specific owner:
`hub clone octocat/Spoon-Knife`

Clone a repository belonging to your user/organization:
`hub clone my-project`

Clone with a specific branch and into a new directory:
`hub clone --branch main octocat/Spoon-Knife my-fork`

PARAMETERS

<REPOSITORY>
    The name of the GitHub repository to clone. This can be in `owner/repo` format or just `repo` if hub can infer the owner.

<DIRECTORY>
    Optional. The name of a new directory to clone into. If not specified, the repository is cloned into a directory named after the repository.

[]
    All unrecognized options are passed directly to `git clone(1)`. Common options include:

  • --bare: Make a bare Git repository.
  • --mirror: Set up a mirror of the remote repository.
  • --depth <num>: Create a shallow clone with a history truncated to the specified number of commits.
  • --branch <name>: Instead of cloning the branch pointed to by the remote HEAD, clone the specified branch.
  • --single-branch: Clone only the history leading to the specified branch.
  • --recursive: After the clone is created, initialize and update submodules.
  • --no-checkout: When cloning a repository, do not checkout any branch on the new working tree.
  • --origin <name>: Use <name> instead of the default 'origin' to name the remote.
Note: This is not an exhaustive list. Refer to `git clone --help` for all options.

DESCRIPTION

hub clone is a specialized command within the hub toolset that streamlines the process of cloning GitHub repositories. It acts as a wrapper around the standard git clone command, adding intelligent defaults and conveniences tailored for GitHub.

Instead of requiring the full `git@github.com:owner/repo.git` or `https://github.com/owner/repo.git` URL, hub clone allows for significantly shorter and more intuitive syntaxes. For example, to clone a repository named `Spoon-Knife` from the user `octocat`, you can simply type `hub clone octocat/Spoon-Knife`. If the repository belongs to the current authenticated user or an organization they are part of, `hub clone my-project` might be sufficient, as hub attempts to infer the owner.

This command automatically handles the construction of the full Git URL (SSH or HTTPS) based on your hub configuration or detected environment, eliminating the need to manually specify protocols. All standard options supported by git clone are transparently passed through, making hub clone a powerful drop-in replacement that enhances productivity for GitHub workflows. It's particularly useful for quickly pulling down projects, contributing to open-source, or managing your own repositories.

CAVEATS

hub clone relies on the hub tool being properly installed and configured to interact with GitHub. It leverages your GitHub authentication (e.g., via `GITHUB_TOKEN` environment variable or hub's own configuration files) to determine the appropriate cloning protocol and user context. Without proper hub setup, it may fall back to standard git clone behavior or fail.

It also inherits all behaviors and potential issues of git clone, as it acts as a wrapper.

<I>PROTOCOL SELECTION</I>

hub clone automatically determines whether to use HTTPS or SSH for cloning based on your hub configuration (e.g., `hub.protocol` in your Git config), presence of `GITHUB_USER` or `GITHUB_TOKEN` environment variables, or if you have SSH keys configured for GitHub. You can explicitly configure the preferred protocol using `git config --global hub.protocol ssh` or `git config --global hub.protocol https`.

<I>ENVIRONMENT VARIABLES</I>

hub clone (and hub in general) can utilize environment variables like `GITHUB_USER` and `GITHUB_TOKEN` for authentication and user context, influencing how it resolves repository paths and authenticates with GitHub.

HISTORY

The hub tool, which includes hub clone, was created to bridge the gap between Git and GitHub, making GitHub's features more accessible from the command line. It emerged as an unofficial but widely adopted extension to Git, providing commands that directly map to common GitHub workflows (like creating pull requests, forking, browsing, and cloning). hub clone specifically addresses the repetitive task of typing full GitHub URLs, simplifying it into a more intuitive experience, much like how GitHub's web interface allows simple `owner/repo` notation. Its development has been community-driven, aiming to enhance the CLI experience for GitHub users.

SEE ALSO

Copied to clipboard