Git Clone
In Git, cloning refers to creating a copy of a target repository, whether it's remote or local. You can clone a remote repository to your system to create a local version, allowing you to sync between the two locations.
Git Clone Command
The 'git clone' command-line utility is used to create a local copy of a remote repository by accessing it via a specified URL.
The original repository is typically hosted on a remote server, such as GitHub, Bitbucket, or GitLab, and its URL is commonly referred to as the origin.
Syntax:
$ git clone <repository URL>
Git Clone Repository
If you want to clone a repository from GitHub or contribute to an existing repository owned by another user, follow these steps to clone the repository:
Step1:
Go to GitHub and navigate to the repository's main page.
Step2:
Click on the "Clone or download" button located below the repository name.
Step3:
In the "Clone with HTTPS" section, copy the repository's clone URL. If the repository is empty, simply copy the URL from your browser and proceed to the next step.
Step4:
Launch Git Bash and navigate to the directory where you want to create the local copy of the repository.
Step5:
Run the 'git clone' command followed by the repository URL to create a local copy of the remote repository. Here's the command:
$ git clone https://github.com/ImDwivedi1/Git-Example.git
Now, press Enter, and your local copy of the cloned repository will be created.
The output will look like this:
Cloning a Repository into a Specific Local Folder
Git allows you to clone a repository into a specific directory without navigating to it first. You can specify the directory as the next argument in the `git clone` command. Here's an example:
$ git clone https://github.com/ImDwivedi1/Git-Example.git "new folder(2)"
This command works the same as the previous one, but it clones the repository into the specified directory.
Git also supports the SSH protocol for transferring repositories. While the previous example uses the 'git://' protocol, you can also use 'http(s)://' or 'user@server:/path.git', which utilizes the SSH transfer protocol.
Git Clone Branch
Git allows you to clone only a specific branch from a repository. You can create a directory for that individual branch using the 'git clone' command. To clone a branch, use the '-b' option followed by the branch name. The syntax for cloning a specific Git branch is as follows:
Syntax:
$ git clone-b <Branch name> < Repository URL>
Here is the command:
$ git clone-b master https://github.com/ImDwivedi1/Git-Example.git "new folder(2)"
In the given output, only the master branch is cloned from the principal repository Git-Example.