Git Clone allows you to copy existing re­pos­it­or­ies and work in the separate clone. You can carry out push and pull commands from the working copy there­after.

Cheap domain names – buy yours now
  • Free website pro­tec­tion with SSL Wildcard included
  • Free private re­gis­tra­tion for greater privacy
  • Free Domain Connect for easy DNS setup

What is Git Clone?

Unlike SVN, Git allows you to work in multiple re­pos­it­or­ies at the same time. This allows de­velopers to test out ad­just­ments without the risk of ruining the entire project, and it also allows teams to work at the same time without waiting for other team members to make any steps.

However, Git Clone means team do not have to start from scratch, as they have the option to copying existing re­pos­it­or­ies and con­tinu­ing to work in the copy. All of the version control processes are then managed using the new local re­pos­it­ory. The clone can be used for all de­vel­op­ment steps. However, the cloning process will auto­mat­ic­ally set a link to the original re­pos­it­ory.

It is important to note that Git makes no dis­tinc­tion between the central re­pos­it­ory and its clones. The clones are perceived as fully valid. Instead of com­mit­ting to the central, original re­pos­it­ory, commits are shared with each other using Git Push and Git Pull.

Tip

You can learn more about the sim­il­ar­it­ies and dif­fer­ences between the Git and SVN man­age­ment tools in our Git vs. SVN com­par­is­on.

What is the Git Clone syntax?

Git Clone is a simple Git Command. It is essential when working on different de­vel­op­ment steps in daily tasks. The syntax of the command is always the same. You can find it in our handy Git cheat sheet with a PDF download. The classic structure looks like this:

git clone <repository></repository>

This command copies the sample re­pos­it­ory and saves the copy on the local machine. The original remains untouched and will not adopt any changes auto­mat­ic­ally. Re­pos­it­or­ies in the local data system and re­pos­it­or­ies on other machines are a suitable basis for Git Clone. These can be accessed using HTTP or SSH. HTTP looks like this:

git clone https://examplesite.com/external_repository.git

This is the syntax if an SSH username is stored already:

git clone ssh://user@example.com/new_repository.git
cd new_repository

How do I set des­tin­a­tion folder?

In addition to the method described above, Git Clone also allows you to select a specific location to store the copy. This can make your work easier and it also provides a better overview. Simply place the des­tin­a­tion folder after the command to do this. This is what the command looks like:

git clone <repository> <destination folder=""></destination></repository>

This clones the re­pos­it­ory and stores the copy in the specified folder. All branches, files and commits are also noted and cloned.

What is Git clone and mirror?

Use “mirror” to create a copy that cannot be edited with Git Clone. This includes branches and ref­er­ences. This is what the command looks like:

git clone --mirror

What is Git clone and bare?

The “bare” argument tells Git to copy the remote re­pos­it­ory, but to ignore the working directory. This means that you can also use the push and pull commands for the copy, but direct editing is not possible. The command looks like this:

git clone --bare

How do I clone a single branch?

You can also clone a single branch. Use Git Clone and the following command to do this:

git clone --single-branch

The main branch is cloned in this case. Cloning another branch must be ex­pli­citly stated. This is the command:

git clone [url] --branch [branch] --chosen-branch

However, you will not usually need to clone in­di­vidu­al branches, just copy the entire re­pos­it­ory instead.

How do I clone specific tags?

You can also clone certain tags with Git Clone. This is what it looks like in code:

git clone --branch <tag> <repository></repository></tag>

What is Git clone and sparse?

When it comes to par­tic­u­larly large re­pos­it­or­ies with numerous branches, it might make sense to only clone the files from the root directory. The argument for this is “sparse”. It makes working on a re­pos­it­ory easier, aids the overview and has a positive effect on per­form­ance. This command looks like this:

git clone --sparse

How do I use templates with Git Clone?

Simply use the ap­pro­pri­ate command to apply a Git template to a cloned re­pos­it­ory. It looks like this:

git clone --template=<template> <repository></repository></template>

This clones the re­pos­it­ory and applies the desired template directly to the local branch.

Tip

There’s no easier way to deploy websites and apps! Deploy Now by IONOS allows you to optimize your workflows and benefit from several useful features. Try out the first month with up to three starter projects for free.

Go to Main Menu