Skip to main content

Git Clone

In Git, cloning is the act of making a copy of any target repository. The target repository can be remote or local. You can clone your repository from the remote repository to create a local copy on your system. Also, you can sync between the two locations.

The git clone command is used to create a local copy of a specific repository or branch within a repository.

Usually, the original repository is located on a remote server, often from a Git hosting service like Gitopia, GitHub, Bitbucket, or GitLab. The remote repository URL is referred to the origin.

Git Clone Syntax:

git clone <repository URL>

Git Clone Common Usage


  • git clone <url>: Clone a repository that already exists on Gitopia, including all of the files, branches, and commits in the repository.

    Example:

    git clone gitopia://gitopia147dgrtq5ywww473uz680fx2ucex9fv3qnw94zm/hello-world


  • git clone <url> "directory-name": Clone the repository into a specific directory without switching to that particular directory.

    Example:

    git clone gitopia://gitopia147dgrtq5ywww473uz680fx2ucex9fv3qnw94zm/hello-world "git-projects"


  • git clone -b <branch-name> [url]: Clone only a specific git branch from a repository.

    Example:

    git clone -b master gitopia://gitopia147dgrtq5ywww473uz680fx2ucex9fv3qnw94zm/hello-world


  • git clone --mirror: Clone a repository but without the ability to edit any of the files. This includes the refs, or branches. You may want to use this if you are trying to create a secondary copy of a repository on a separate remote and you want to match all of the branches. This may occur during configuration using a new remote for your Git hosting, or when using Git during automated testing.

    Example:

    git clone --mirror gitopia://gitopia147dgrtq5ywww473uz680fx2ucex9fv3qnw94zm/hello-world


You can learn more about the git clone command and its options in git-scm's documentation.