> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/containerized-steps/git-clone-step.md).

# Git Clone step

Add a Git Clone step to clone a repository into the CD stage's workspace.

By cloning the repository, you gain access to the necessary code, scripts, or configurations, enabling you to perform various actions and ensure a reliable and controlled deployment.

<details>

<summary>Example uses cases for cloning a repository in a CD stage</summary>

1. **Accessing deployment scripts or configuration files**:
   * Cloning a repository allows you to access deployment scripts, configuration files, or other resources needed for the deployment process. By cloning the repository, you can ensure that the latest versions of these files are used in the deployment, providing consistency and avoiding potential issues caused by outdated or mismatched files.
2. **Retrieving application or infrastructure definitions**:
   * In cases where the CD process involves deploying an application or provisioning infrastructure, cloning the repository enables you to retrieve the application's source code or the infrastructure-as-code (IaC) definitions. By having the codebase or infrastructure definitions locally, you can perform necessary tasks such as building the application image or running tests.
3. **Branch or commit specific deployments**:
   * Cloning the repository allows for branch or commit-specific deployments. For instance, you might have a CD pipeline that triggers deployments based on specific branches, such as staging or release branches. By cloning the repository, you can isolate the relevant code for the specific branch or commit and perform targeted deployments.
4. **Performing custom build or pre-deployment actions**:
   * Cloning a repository provides the opportunity to perform custom build or pre-deployment actions. These actions might involve running additional tests, compiling assets, generating documentation, or preparing the application or infrastructure for deployment. By cloning the repository, you have full control over the deployment process and can add any necessary steps before deploying.
5. **Verifying deployment artifacts**:
   * Cloning the repository allows you to verify the integrity and consistency of the deployment artifacts. By comparing the cloned repository with the expected state or predefined configurations, you can ensure that the correct files and versions are being deployed, reducing the risk of deploying incorrect or unauthorized code or configurations.

</details>

### Add the Git Clone step <a href="#add-the-git-clone-step" id="add-the-git-clone-step"></a>

The Git Clone step uses a containerized step group. For more information, go to [Containerize step groups](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/containerized-steps/containerized-step-groups.md).

{% tabs %}
{% tab title="YAML" %}

```
- step:
   type: GitClone
   name: GitClone_1
   identifier: GitClone_1
   spec:
     connectorRef: account.GitConnectorBzGN8G1COj
     repoName: myrepo
     build:
       type: branch
       spec:
         branch: main
```

{% endtab %}

{% tab title="Harness Manager" %}

1. In your Harness Deploy stage, in **Execution**, select **Add Step**.
2. Select **Git Clone**.
3. Configure the steps using the settings described below.
   {% endtab %}
   {% endtabs %}

### Connector <a href="#connector" id="connector"></a>

Select a connector for the source control provider hosting the code repository that you want the step to clone.

The following topics provide more information about creating code repo connectors:

* Azure Repos: [Connect to Azure Repos](/harness-ai/use-harness-platform/connectors/code-repositories/connect-to-a-azure-repo.md)
* Bitbucket: [Bitbucket connector settings reference](/harness-ai/use-harness-platform/connectors/code-repositories/ref-source-repo-provider/bitbucket-connector-settings-reference.md)
* GitHub: [GitHub connector settings reference](/harness-ai/use-harness-platform/connectors/code-repositories/ref-source-repo-provider/git-hub-connector-settings-reference.md)
* GitLab: [GitLab Connector Settings reference](/harness-ai/use-harness-platform/connectors/code-repositories/ref-source-repo-provider/git-lab-connector-settings-reference.md)
* Other Git providers:
  * [Git connector settings reference](/harness-ai/use-harness-platform/connectors/code-repositories/ref-source-repo-provider/git-connector-settings-reference.md)
  * [Connect to an AWS CodeCommit Repo](/harness-ai/use-harness-platform/connectors/code-repositories/connect-to-code-repo.md)

### Repository Name <a href="#repository-name" id="repository-name"></a>

If the connector's [URL Type](/harness-ai/use-harness-platform/connectors/code-repositories/ref-source-repo-provider/git-connector-settings-reference.md#url-type) is **Repository**, then **Repository Name** is automatically populated based on the repository defined in the connector's configuration.

If the connector's URL Type is **Account**, then you must specify the name of the code repository that you want to clone into the stage workspace.

### Build Type, Branch Name, and Tag Name <a href="#build-type-branch-name-and-tag-name" id="build-type-branch-name-and-tag-name"></a>

For **Build Type**, select **Git Branch** if you want the step to clone code from a specific branch within the repository, or select **Git Tag** if you want the step to clone code from a specific commit tag. Based on your selection, specify a **Branch Name** or **Tag Name**.

{% hint style="info" %}
You can use [fixed values, runtime input, or variable expressions](/harness-ai/use-harness-platform/variables-and-expressions/runtime-inputs.md) for the branch and tag names. For example, you can enter `<+input>` for the branch or tag name to supply a branch or tag name at runtime.
{% endhint %}

### Clone directory <a href="#clone-directory" id="clone-directory"></a>

An optional target path in the stage workspace where you want to clone the repo.

### Depth <a href="#depth" id="depth"></a>

The number of commits to fetch when the step clones the repo.

The default depth is `0`, which fetches all commits from the relevant branch.

For more information, go to the [git clone documentation](https://git-scm.com/docs/git-clone).

### SSL Verify <a href="#ssl-verify" id="ssl-verify"></a>

If **True**, which is the default value, the pipeline verifies your Git SSL certificates. The stage fails if the certificate check fails. Set this to **False** only if you have a known issue with the certificate and you are willing to run your stages anyway.

### Run as User <a href="#run-as-user" id="run-as-user"></a>

Specify the user Id to use to run all processes in the pod if running in containers. For more information, go to [Set the security context for a pod](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod). This value defaults to `1000` if left unconfigured.

### Set Container Resources <a href="#set-container-resources" id="set-container-resources"></a>

Maximum resource limits for containers that clone the codebase at runtime. For more information, go to [Resource units in Kubernetes](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#resource-units-in-kubernetes).

### Advanced settings <a href="#advanced-settings" id="advanced-settings"></a>

In **Advanced**, you can use the following options:

* [Conditional Execution](/harness-ai/use-harness-platform/pipelines/step-skip-condition-settings.md)
* [Failure Strategy](/harness-ai/use-harness-platform/pipelines/failure-handling/define-a-failure-strategy-on-stages-and-steps.md)
* [Looping Strategy](/harness-ai/use-harness-platform/pipelines/looping-strategies/looping-strategies-matrix-repeat-and-parallelism.md)
* [Policy Enforcement](/harness-ai/use-harness-platform/governance/policy-as-code/harness-governance-overview.md)
