> 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

Clone a repository into a Continuous Delivery stage workspace

Add a Git Clone step to clone a repository into the Continuous Delivery stage workspace. The clone gives later steps access to the code, scripts, or configuration in that repository.

<details>

<summary>Example use cases for cloning a repository in a Continuous Delivery stage</summary>

1. **Accessing deployment scripts or configuration files**: Cloning a repository gives you access to deployment scripts, configuration files, or other resources needed for the deployment. The clone uses the latest versions of these files, which keeps the deployment consistent and avoids issues caused by outdated or mismatched files.
2. **Retrieving application or infrastructure definitions**: When the Continuous Delivery process deploys an application or provisions infrastructure, cloning the repository retrieves the application source code or the infrastructure-as-code (IaC) definitions. With the codebase or infrastructure definitions in the stage workspace, you can build the application image or run tests.
3. **Branch or commit specific deployments**: Cloning the repository supports branch or commit-specific deployments. For instance, a Continuous Delivery pipeline can trigger deployments from specific branches, such as staging or release branches. The clone isolates the code for that branch or commit.
4. **Performing custom build or pre-deployment actions**: Cloning a repository lets you run custom build or pre-deployment actions. These actions can include running additional tests, compiling assets, generating documentation, or preparing the application or infrastructure for deployment.
5. **Verifying deployment artifacts**: Cloning the repository lets you verify the integrity and consistency of the deployment artifacts. Compare the cloned repository with the expected state or predefined configurations to confirm that the correct files and versions are deployed, and that incorrect or unauthorized code or configuration is not deployed.

</details>

***

## What you will learn from this topic

* How to [add a Git Clone step](#add-the-git-clone-step) in a containerized step group
* How to [select the connector](#connector) and [repository name](#repository-name)
* How to [clone a branch or a tag](#build-type-branch-name-and-tag-name)
* How to [set the clone directory](#clone-directory), [fetch depth](#depth), and [SSL verification](#ssl-verify) so the step clones the selected commit into the stage workspace

***

## Before you begin

* **Containerized step group**: The Git Clone step runs in a containerized step group. Go to [Containerize step groups](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/containerized-steps/containerized-step-groups.md) to enable container-based execution.
* **Code repository connector**: You need a connector for the Git provider that hosts the repository. Go to [Connect to a Git repository](https://developer.harness.io/docs/platform/connectors/code-repositories/connect-to-code-repo/) to create one.

***

## 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. Go to [Containerize step groups](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/containerized-steps/containerized-step-groups.md) to enable container-based execution.

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

```yaml
- step:
    type: GitClone
    name: GitClone_1
    identifier: GitClone_1
    spec:
      connectorRef: account.<git-connector>
      repoName: myrepo
      build:
        type: branch
        spec:
          branch: main
```

{% endtab %}

{% tab title="Harness Manager" %}
Perform the following steps to add the Git Clone step:

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

***

## Git Clone step settings

The following settings control which repository the step clones and how the clone runs.

### 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 explain how to create code repository connectors:

* Azure Repos: Go to [Connect to Azure Repos](https://developer.harness.io/docs/platform/connectors/code-repositories/connect-to-a-azure-repo/) to create the connector.
* Bitbucket: Go to [Bitbucket connector settings reference](https://developer.harness.io/docs/platform/connectors/code-repositories/ref-source-repo-provider/bitbucket-connector-settings-reference/) to configure the connector.
* GitHub: Go to [GitHub connector settings reference](https://developer.harness.io/docs/platform/connectors/code-repositories/ref-source-repo-provider/git-hub-connector-settings-reference/) to configure the connector.
* GitLab: Go to [GitLab connector settings reference](https://developer.harness.io/docs/platform/connectors/code-repositories/ref-source-repo-provider/git-lab-connector-settings-reference/) to configure the connector.
* Other Git providers: Go to [Git connector settings reference](https://developer.harness.io/docs/platform/connectors/code-repositories/ref-source-repo-provider/git-connector-settings-reference/) to configure a platform-agnostic Git connector, or go to [Connect to AWS CodeCommit](https://developer.harness.io/docs/platform/connectors/code-repositories/connect-to-code-repo/#connect-to-aws-codecommit) to connect to AWS CodeCommit.

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

If the connector's [URL Type](https://developer.harness.io/docs/platform/connectors/code-repositories/ref-source-repo-provider/git-connector-settings-reference#url-type) is **Repository**, then **Repository Name** is automatically populated from the repository defined in the connector configuration.

If the connector's URL Type is **Account**, then you must specify the name of the code repository 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** to clone code from a specific branch in the repository, or select **Git Tag** to clone code from a specific commit tag. Based on your selection, specify a **Branch Name** or **Tag Name**.

{% hint style="info" %}
**Runtime values**

You can use [fixed values, runtime input, or variable expressions](https://developer.harness.io/docs/platform/variables-and-expressions/runtime-inputs) for the branch and tag names. For example, enter `<+input>` for the branch or tag name to supply that name at runtime.
{% endhint %}

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

**Clone directory** is an optional target path in the stage workspace where the step clones the repository.

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

**Depth** is the number of commits to fetch when the step clones the repository.

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

Go to the [git clone documentation](https://git-scm.com/docs/git-clone) to review the fetch depth option.

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

If **SSL Verify** is **True**, which is the default, the pipeline verifies the Git SSL certificates. The stage fails if the certificate check fails. Set this to **False** only when the certificate has a known issue and the stage should run anyway.

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

Specify the user ID used to run all processes in the pod when the step runs in containers. 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) to review this Kubernetes setting. This value defaults to `1000` when 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. Go to [Resource units in Kubernetes](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#resource-units-in-kubernetes) to review resource units.

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

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

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

***

## Next steps

* Go to [Containerize step groups](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/containerized-steps/containerized-step-groups.md) to run the Git Clone step on your Kubernetes cluster.
* Go to [Connect to a Git repository](https://developer.harness.io/docs/platform/connectors/code-repositories/connect-to-code-repo/) to create the connector this step uses.
* Go to [Conditional executions for stages and steps](https://developer.harness.io/docs/platform/pipelines/step-skip-condition-settings) to control when the step runs.
* Go to [Define failure strategies for stages and steps](https://developer.harness.io/docs/platform/pipelines/failure-handling/define-a-failure-strategy-on-stages-and-steps) to configure what happens if the clone fails.

{% @harness-feedback/feedback %}
