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. This is achieve by the git clone command.
The git clone is a command-line utility which is used to make a local copy of a remote repository. It accesses the repository through a remote URL.
Usually, the original repository is located on a remote server, often from a Git service like GitHub, Bitbucket, or GitLab. The remote repository URL is referred to the origin.
$ git clone <repository URL>
The example below demonstrates how to obtain a local copy of a central repository stored on a server accessible at example.com using the SSH username john:
git clone ssh://email@example.com/path/to/my-project.git
# Start working on the project
The first command initializes a new Git repository in the my-project folder on your local machine and populates it with the contents of the central repository. Then, you can cd into the project and start editing files, committing snapshots, and interacting with other repositories. Also note that the .git extension is omitted from the cloned repository. This reflects the non-bare status of the local copy.
Cloning to a specific folder
git clone <repo> <directory>
Clone the repository located at ＜repo＞ into the folder called ~＜directory＞! on the local machine.
Cloning a specific tag
git clone –branch <tag> <repo>
Clone the repository located at ＜repo＞ and only clone the ref for ＜tag＞.
git clone -branch
The -branch argument lets you specify a specific branch to clone instead of the branch the remote HEAD is pointing to, usually the main branch. In addition you can pass a tag instead of branch for the same effect.
git clone -branch new_feature git://remoterepository.git
This above example would clone only the new_feature branch from the remote Git repository. This is purely a convenience utility to save you time from downloading the HEAD ref of the repository and then having to additionally fetch the ref you need.
git clone –bare
Similar to git init –bare, when the -bare argument is passed to git clone, a copy of the remote repository will be made with an omitted working directory. This means that a repository will be set up with the history of the project that can be pushed and pulled from, but cannot be edited directly. In addition, no remote branches for the repo will be configured with the -bare repository. Like git init –bare, this is used to create a hosted repository that developers will not edit directly.
git clone –mirror
Passing the –mirror argument implicitly passes the –bare argument as well. This means the behavior of –bare is inherited by –mirror. Resulting in a bare repo with no editable working files. In addition, –mirror will clone all the extended refs of the remote repository, and maintain remote branch tracking configuration. You can then run git remote update on the mirror and it will overwrite all refs from the origin repo. Giving you exact ‘mirrored’ functionality.
Git URL protocols:
Secure Shell (SSH) is a ubiquitous authenticated network protocol that is commonly configured by default on most servers. Because SSH is an authenticated protocol, you’ll need to establish credentials with the hosting server before connecting. ssh://[user@]host.xz[:port]/path/to/repo.git/
A protocol unique to git. Git comes with a daemon that runs on port (9418). The protocol is similar to SSH however it has NO AUTHENTICATION. git://host.xz[:port]/path/to/repo.git/
Hyper text transfer protocol. The protocol of the web, most commonly used for transferring web page HTML data over the Internet. Git can be configured to communicate over HTTP http[s]://host.xz[:port]/path/to/repo.git/
For more Git Related post click here.