Clone
Clone your Harness Code repos to your local machine
After you create a repository, you can work directly in the Harness Code UI, or clone the repository to your local machine and use your own IDE. Harness Code supports cloning over HTTPS and over SSH.
Before you begin
Repository access: You need View on the repository you want to clone, and Push if you intend to push changes back. Go to the permissions reference to review the permission list.
Git installed: You need a local Git client. Partial clone requires Git 2.19 or later, so upgrade if you plan to use
--filter.SSH availability: Cloning over SSH is behind the
CODE_SSH_ENABLEDfeature flag. Contact Harness Support to enable it.
Clone over HTTPS
To clone a repository over HTTPS, do the following:
When viewing a repository in Harness Code, go to Summary, then select Clone repository.
If this is the first time you have cloned this repository, select Generate Clone Credentials, then copy the Token and store it somewhere secure. Clone credentials are shown only once.
When you select Generate Clone Credentials, Harness Code creates an API token in your user profile.
Tokens carry many privileges. Treat your user tokens as passwords and store them securely.
Copy the Git clone URL shown on the Clone dropdown, then use it to clone the repository through the Git command line or your preferred Git GUI tool.
Git prompts you for your Harness user name and the API token that was shown when you generated clone credentials.
Work with the cloned repository as you would with any other Git repository, by creating commits, pushing to the remote, and pulling changes.
Clone over SSH
Cloning over SSH suits you if you prefer key-based authentication over token-based authentication.
Add your SSH key to Harness
Before you clone over SSH, confirm you have a key pair and register the public key with Harness.
Check whether an SSH key pair exists on your machine:
If the file does not exist, generate a key pair and press Enter to accept the defaults:
In the bottom-left corner of the Harness UI, click your Profile icon.
Select + SSH Key.
Enter a name for the key, then paste your public SSH key.
Click Save.
Paste the contents of your public key file, not the private key.
Clone with the SSH URL
To clone a repository over SSH, do the following:
In Harness, navigate to the repository you want to clone, then copy its SSH URL.
Select SSH in the Clone dropdown to reveal the SSH URL.
The URL uses the following format:
From your terminal, run
git clonewith the URL in quotes:For example:
Change into the cloned directory and verify the remote:
The SSH URL appears as
origin.
Reduce transfer size with partial and shallow clone
By default, git clone downloads the entire commit history along with every blob and tree, which costs bandwidth and time on large monorepos and multi-service repositories. Harness Code supports Git filtering so you can avoid that cost.
Use the --filter flag to exclude blobs from the initial clone. Git fetches them lazily when you need them:
Combine filtering with a shallow clone to also truncate history:
Go to the Git documentation for --filter to review the full filter specification.
Troubleshooting
Next steps
You have a local copy of your repository and know how to keep the initial transfer small.
Git LFS: Store files of 1 GiB or more outside the main object store.
Branch: Create and manage branches in your clone.
Sign commits: Prove authorship on the commits you push back.
Last updated
Was this helpful?