Open In App

What is Git Clone?

Last Updated : 17 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Git Clone will make a copy of the existing git repository in the local machine. This means it will download all the files and directories which are available in the repository available in the remote repository. Git clone will make the repository online which will help us to test the new features before merging into the main or production branch.

Git Clone

The git clone command is used to create a copy of a specific repository or branch within a repository. When you clone a repo you get a copy of the entire history of the repo. The command used for cloning any repository is:

git clone <repository-link>

For Example: If you want to clone the Bootstrap repository.

GitHub Repository URL

 

In the above image, It’s a Bootstrap repository and you want to clone it in your local system. For this, you have to use the link to clone this repository on your computer. First, you have to go inside the folder in which you want to clone the repository, for this use the cd command

Git Branch

 

After that, Clone the repository using git clone <repo-link>

Git clone repo link

 

Here the cloning process starts and it is in 14% progress and it continues until 100%. 

Clonning the repository

When the process is complete, the bootstrap repo is added to your local computer inside the Git folder, you can now cd into the bootstrap repo and work accordingly.

git log

If you want to terminate the process then press control C.

Terminate the proceses

Git Clone With Username And Password

When you are cloning the git repository with the help of https URL then you need to use the username and the password as mentioned below.

git clone https://username:password@github.com/username/repository.git

In the place of “Username” and “Password” give your credentials.

In the real time it is not at all reccamonded to use the password and username directly because of securtity concerns instead of that you can use the credential manager or an access token instead of a password.

Git Clone Branch

You can also make a directory for a particular branch by using the git clone command. For this, you need to specify the branch name with the -b command as follows.

Syntax:

git clone -b <Branch name> <Repository URL>

When you do not specify the branch it clones the repo in the main branch.

Purpose: Repo-To-Repo Collaboration Development Copy

Repo-to-repo collaboration development copy is a process of using version control systems which will copy the repository which is avalible in the remote can be copied to the local machine and make the changes and push back to the remote location where other developers can work on it.

To clone the remote repoisitory use the following command.

git clone <remote_repository_url>

Make the changes the as you want and again push it to the remote repository.

Git Clone -Branch

Git clone branch is used to clone the branch which required and presnt in the remote git repository to local machine. Following is the command which is used to clone the repository to the local machine.

git clone –branch <branch_name> <remote_repository_url>

In the above the branch name describes the name of the branch which you to clone and the repository URL will the ssh url of the branch in the remote repository.

Git Clone -Mirror vs. Git Clone -Bare

Git Clone -Mirror

Git Clone -Bare

Git Clone -Mirror create an complete copy of the git remote repository or complete mirror of the git repository.

Git Clone -Bare will only copies the file which are required for the keeping the track of that repository.

Git Clone -Mirror it will have the all the copies of the files which are exactly present in the remote git repository.

Git Clone -Bare will only keeps the files which are necessary to keep the track.

Mostly used for the backup purposes

Mostly used for the continuous integration.

It can also be used for the offline development purpose.

It can also be used for the working on the same repsitory on multiple locations.

Git URLs

The code which is stored in the git remote repositories are need to be accesed or to be cloned in to the local repositories for that git URL’s will acts as an git web address.

Types of Git URL’s

  1. HTTPS
  2. SSH
  3. Git Protocol
  4. Local File System
  5. Relative File System
  6. Git Bundle
  7. HTTP/HTTPS with Git Smart Protocol

Mostly used are the HTTP’s and SSH URL’s “https://github.com/username/repository.git” https is ude for cloning and pushing the repositories and this is for “git@github.com:username/repository.git” used for the same cloning and pushing repositories.

Cloning a Repository into a Specific Local Folder

Follow the steps mentioned below to clone Repository into a Specific Local Folder.

Step 1: Clone the repository into specific local floder.

git clone <repository_url> <local_folder>

Replace the URL with the URL that that you want tot clone and mentione the name of the floder which you want to copy in the palce of the <local_floder>.

FAQs On Git Clone

1.Is git clone the same as a download?

When you download a repository, it gives you all the source files but it does not contain .git files. When you clone a repository, you get a copy of the entire history.

2. Git Clone With Token

Use the following command to use an access token

git clone https://<username>:<token>@github.com/<username>/<repository>.git

3. Git Clone Branch

By using the following command you can clone the specific required to your local repository.

git clone -b <branch-name> <remote-repository-URL>

-b or — branch tells the branch which we need to clone.

4. Git clone vs Git pull

  • Git Clone: Git clone will make an copy of the repository which is already exists in the remote location.
  • Git Pull: Git pull is used to fetch the latest changes from the remote repository and merge them into your local repository.



Previous Article
Next Article

Similar Reads

Difference Between Git remote prune, Git prune and Git fetch --prune
One of the great things about Git is that it's *very careful about deleting data*. This makes it pretty hard to lose commits or other valuable data in Git! A small downside of this is that you might sometimes see stale data that you actually don't need anymore. One of the best examples of this is references to remote branches that have already been
2 min read
How to Clone Web Project from GitHub in Pycharm using Git?
PyCharm is one of the most popular Python-IDE developed by JetBrains used for performing scripting in Python language. PyCharm is an integrated development environment used in computer programming. PyCharm provides some very useful features like Code completion and inspection, Debugging process, support for various programming frameworks such as Fl
2 min read
Shallow Clone on Git in Linux
Git is tracking-based software used to track the changes made in a project. It is a distributed version control system. Software developers use it to collaborate on source code remotely. This allows the developers to create the software even when they are working professionals and contribute to the open-source. What is Shallow Clone on Git? Shallow
3 min read
How to Clone all Remote Branches in Git?
Cloning a repository is a common task when working with Git, but what if you need all the branches from a remote repository? By default, Git clones only the default branch (usually 'master' or 'main'). However, you may need access to all remote branches in many scenarios. This article will guide you through the process of cloning all remote branche
2 min read
Git Shallow Clone: Optimizing Repository Size
Git is an important tool for version control, known for its ability to manage projects with complex histories efficiently. However, as projects grow and their histories expand, the size of the repositories can become larger, impacting performance and increasing clone times. This is where Git's shallow clone functionality becomes important. Table of
4 min read
Difference between “git add -A” and “git add”
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. It is basically, software for tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development. Featu
3 min read
Git - Difference Between Git Revert, Checkout and Reset
While Working with Git in certain situations we want to undo changes in the working area or index area, sometimes remove commits locally or remotely and we need to reverse those changes. There are 3 different ways in which we can undo the changes in our repository, these are git reset, git checkout, and git revert. git checkout and git reset in fac
7 min read
Git - git-show Command Line Utility
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git relies on the basis of distributed development of software where more than one developer may have access to the source code of a specific application and can modify changes to it that may be
3 min read
Git - git-prune
Git prune is a command that deletes all the files that are not reachable from the current branch. The prune command is useful when you have a lot of files in your working directory that you don’t want to keep. The primary use of git prune is to clean up your working directory after you have finished working on a project. What actually git prune doe
4 min read
Git LFS: Managing Large Files in Git Repositories
Git, undoubtedly one of the most popular version control systems, is widely used for managing source code in software development projects. However, one of its limitations is its handling of large files. Traditional Git repositories struggle to efficiently manage large files, leading to bloated repositories and slow performance. This is where Git L
4 min read
Article Tags :