How to clone a GIT Repository


Clone a Repository:

This will create a new directory named after the repository in your current working directory, and copy all the files and history from the remote repository to your local machine.

git clone <repository URL>
git clone https://github.com/jayaram509/gitdemo.git

Clone a Repository into a Directory

You can also specify a directory name to clone into using the following command:

git clone <repository URL> <directory name>

For example:This will clone the repository into a directory named git-demo-repo

git clone https://github.com/jayaram509/gitdemo.git git-demo-repo

Clone a Specific Branch

To clone a specific branch of a repository, you can use the following command:

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

For example:This will clone only the “dev” branch of the repository.

git clone -b dev https://github.com/jayaram509/gitdemo.git

Clone to Depth of commits

You can also clone a repository to a specific commit using the following command:

git clone <repository URL> --depth <number of commits>

For example:This will clone the repository with only the most recent commit, making it faster and more space-efficient

git clone https://github.com/jayaram509/gitdemo.git --depth 1