---
title: "Clone URLs — Git for Laravel | Roundly"
description: "Build authenticated HTTPS clone URLs from a static token, an OAuth grant or a GitHub App installation token."
url: https://roundly-consulting.com/open-source/docs/git-for-laravel/clone-urls
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Git for Laravel](https://roundly-consulting.com/open-source/docs/git-for-laravel.md)

# Clone URLs

repo($path)->cloneUrl() builds an authenticated HTTPS clone URL for deploy and CI steps — no manual URL assembly:

```php
use RoundlyConsulting\Git\Dto\Credentials\Token;

$url = Git::github()->repo('acme/api')->cloneUrl('acme', Token::from('ghp_...'));
// https://token:ghp_...@github.com/acme/api.git
```

To clone with the credential the package itself is configured with, read it off the facade:

```php
use RoundlyConsulting\Git\Enums\ProviderName;

$credentials = Git::credentials(ProviderName::Github); // ?Credentials — app installation, else token, else null
$url = Git::github()->repo('acme/api')->cloneUrl('acme', $credentials);
```

A refreshable credential is asked for a live token instead of being read for a static one, and an installation token gets GitHub’s documented username:

```php
$url = Git::github()->repo('acme/api')->cloneUrl('acme', $installationCredentials);
// https://x-access-token:ghs_...@github.com/acme/api.git
```

## Per provider

| Provider | Username in the URL | Host |
| --- | --- | --- |
| GitHub | x-access-token for a GithubAppToken, token for any other credential | The web host derived from the API URL — a leading api. label dropped, or a trailing /api/v3 on Enterprise Server |
| GitLab | oauth2 | The configured GitLab URL |
| Bitbucket | The $username you pass | The web host derived from the API URL — a leading api. label dropped |

## Worth knowing

- For an installation credential this is a network call — it mints a token or reads a cached one — so a loop over N repositories is N mints on a cold cache.
- A GithubApp credential is refused: the app’s own JWT can mint a token for every installation of the app, and a clone URL ends up in git remote and in process environments.
- The username and secret are percent-encoded, so a credential containing @, / or : still yields a URL whose host is the forge (me@acme.io / p@ss → https://me%40acme.io:p%40ss@…).
- Scope the installation token to the repository you clone — see Scoped tokens & installations.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/git-for-laravel.md)
