GIT Clone command with examples.
Cloning is the process of creating a duplicate of something. The Git clone command creates a copy of the central repository in your workspace.
This is the first step a developer takes prior to starting any code changes. The original repository could be located on a LAN machine or over a hosted code management service like BitBucket, Gitlab, or GitHub.
The origin is the URL that points to the central repository.
What do you need to clone a remote repository?
Typically, the origin is located on a server that is connected to the developer machine via an IP network. You must ensure that the local machine is connected to the server. For cloning, you must install the git software. The software client may include both a graphical user interface and a command-line interface. You can find installation instructions here.
In this tutorial, we’ll use Linux’s command-line interface. The same will be true for the Windows operating system.
How to know the repository URL?
How to clone a repository explained with examples?
The clone is a very simple command to use. Usually, the minimum requires the origin URL only. But it gives some options for additional features.
The following explains all possible options for the command.
Address of origin (repository URL path) –
This is the first argument to the command. It could be an HTTP, HTTPS, FTP, or SSH URL with a domain name or IP address along with the name of the repository, such as https://github.com/cspsprotocol/projectsource.git
git clone https://github.com/cspsprotocol/projectsource.git
Name of the folder (directory name) –
It is the name of the directory that the git clone command will use to copy all the source code. By default, the folder name will be the name of the repository without the .git suffix.
git clone https://github.com/cspsprotocol/projectsource.git folder-name
Clone all submodules (–recurse-submodules) –
A repository’s submodule is another repository. It could be a piece of third-party code or an entirely separate codebase. By default, the clone command does not include submodules while copying. This option copies and initializes all submodules.
Clone a branch with option -b.
In Git, a branch is a copy of the base repository with its own commit history. Developers create branches to implement specific features and merge them into the base branch.
The cloning process copies code from the master into a local directory by default. By specifying the -b option, you may clone a specific branch of code.