How to Clone Repository in Git

Last updated on May 28 2022
Meetesh Jain

Table of Contents

How to Clone Repository in Git

Git Clone

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.

How to Clone Repository in Git
How to Clone Repository in Git

 

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.

Syntax:

1. $ git clone <repository URL>

Git Clone Repository

Suppose, you want to clone a repository from GitHub, or have an existing repository owned by any other user you would like to contribute. Steps to clone a repository are as follows:

Step 1:

Open GitHub and navigate to the main page of the repository.

Step 2:

Under the repository name, click on Clone or download.

How to Clone Repository in Git
How to Clone Repository in Git

Step 3:

Select the Clone with HTTPs section and copy the clone URL for the repository. For the empty repository, you can copy the repository page URL from your browser and skip to next step.

How to Clone Repository in Git
How to Clone Repository in Git

Step 4:

Open Git Bash and change the current working directory to your desired location where you want to create the local copy of the repository.

Step 5:

Use the git clone command with repository URL to make a copy of the remote repository. See the below command:
1. $ git clone https://github.com/ImDwivedi1/Git-Example.git

Now, Press Enter. Hence, your local cloned repository will be created. See the below output:

How to Clone Repository in Git
How to Clone Repository in Git

Cloning a Repository into a Specific Local Folder

Git allows cloning the repository into a specific directory without switching to that particular directory. You can specify that directory as the next command-line argument in git clone command. See the below command:

1. $ git clone https://github.com/ImDwivedi1/Git-Example.git “new folder(2)”

How to Clone Repository in Git
How to Clone Repository in Git

The given command does the same thing as the previous one, but the target directory is switched to the specified directory.

Git has another transfer protocol called SSH protocol. The above example uses the git:// protocol, but you can also use http(s):// or user@server:/path.git, which uses the SSH transfer protocol.

Git Clone Branch

Git allows making a copy of only a particular branch from a repository. You can make a directory for the individual branch by using the git clone command. To make a clone branch, you need to specify the branch name with -b command. Below is the syntax of the command to clone the specific git branch:

Syntax:

1. $ git clone -b <Branch name><Repository URL>

See the below command:

1. $ 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.

How to Clone Repository in Git
How to Clone Repository in Git

So, this brings us to the end of blog. This Tecklearn ‘How to Clone Repository in Git’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Git and GitHub and build a career in DevOps domain, then check out our interactive, Version control with Git and GitHub Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

Version Control with Git and GitHub

Version Control with Git and GitHub Training

About the Course

Tecklearn has specially designed this Git and GitHub Training Course to advance your skills for a successful career in this domain. The course will cover different components of Git and GitHub and how they are used in software development operations. The course consists of important concepts like: branching & merging, how to deal with conflicts, rebasing, merge strategies, Git workflows and so on. You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Git.

Why Should you take Git and GitHub Training?

• Average salary of Git and GitHub Professional is $85k – Indeed.com
• Amazon, Google, Facebook, Microsoft, Twitter, & many other MNC’s worldwide use Git across industries.
• According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.

What you will Learn in this Course?

Introduction to DevOps

• What is Software Development
• Software Development Life Cycle
• Why DevOps?
• What is DevOps?
• DevOps Lifecycle
• DevOps Tools
• Benefits of DevOps
• How DevOps is related to Agile Delivery
• DevOps Implementation

Git and GitHub

• What is version control
• Version Control System (VCS) Products
• Types of VCS
• What is Git
• Why Git for your organization
• Install Git
• Common commands in Git
• Working with Remote Repositories
• GitHub
• Git Installation
• Git Lifecycle
• GitHub (Push, Pull Request)
• GitHub Workflow

 

0 responses on "How to Clone Repository in Git"

Leave a Message

Your email address will not be published. Required fields are marked *