|
| 1 | +# Git credentials |
| 2 | + |
| 3 | +uv allows packages to be installed from private Git repositories using SSH or HTTP authentication. |
| 4 | + |
| 5 | +## SSH authentication |
| 6 | + |
| 7 | +To authenticate using an SSH key, use the `ssh://` protocol: |
| 8 | + |
| 9 | +- `git+ssh://git@<hostname>/...` (e.g., `git+ssh://[email protected]/astral-sh/uv`) |
| 10 | +- `git+ssh://git@<host>/...` (e.g., `git+ssh://[email protected]/astral-sh/uv`) |
| 11 | + |
| 12 | +SSH authentication requires using the username `git`. |
| 13 | + |
| 14 | +See the |
| 15 | +[GitHub SSH documentation](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/about-ssh) |
| 16 | +for more details on how to configure SSH. |
| 17 | + |
| 18 | +### HTTP authentication |
| 19 | + |
| 20 | +To authenticate over HTTP Basic authentication using a password or token: |
| 21 | + |
| 22 | +- `git+https://<user>:<token>@<hostname>/...` (e.g., |
| 23 | + `git+https://git:[email protected]/astral-sh/uv`) |
| 24 | +- `git+https://<token>@<hostname>/...` (e.g., `git+https://[email protected]/astral-sh/uv`) |
| 25 | +- `git+https://<user>@<hostname>/...` (e.g., `git+https://[email protected]/astral-sh/uv`) |
| 26 | + |
| 27 | +!!! note |
| 28 | + |
| 29 | + When using a GitHub personal access token, the username is arbitrary. GitHub doesn't allow you to |
| 30 | + use your account name and password in URLs like this, although other hosts may. |
| 31 | + |
| 32 | +If there are no credentials present in the URL and authentication is needed, the |
| 33 | +[Git credential helper](#git-credential-helpers) will be queried. |
| 34 | + |
| 35 | +## Persistence of credentials |
| 36 | + |
| 37 | +When using `uv add`, uv _will not_ persist Git credentials to the `pyproject.toml` or `uv.lock`. |
| 38 | +These files are often included in source control and distributions, so it is generally unsafe to |
| 39 | +include credentials in them. |
| 40 | + |
| 41 | +If you have a Git credential helper configured, your credentials may be automatically persisted, |
| 42 | +resulting in successful subsequent fetches of the dependency. However, if you do not have a Git |
| 43 | +credential helper or the project is used on a machine without credentials seeded, uv will fail to |
| 44 | +fetch the dependency. |
| 45 | + |
| 46 | +You _may_ force uv to persist Git credentials by passing the `--raw` option to `uv add`. However, we |
| 47 | +strongly recommend setting up a [credential helper](#git-credential-helpers) instead. |
| 48 | + |
| 49 | +## Git credential helpers |
| 50 | + |
| 51 | +Git credential helpers are used to store and retrieve Git credentials. See the |
| 52 | +[Git documentation](https://git-scm.com/doc/credential-helpers) to learn more. |
| 53 | + |
| 54 | +If you're using GitHub, the simplest way to set up a credential helper is to |
| 55 | +[install the `gh` CLI](https://github.com/cli/cli#installation) and use: |
| 56 | + |
| 57 | +```console |
| 58 | +$ gh auth login |
| 59 | +``` |
| 60 | + |
| 61 | +See the [`gh auth login`](https://cli.github.com/manual/gh_auth_login) documentation for more |
| 62 | +details. |
| 63 | + |
| 64 | +!!! note |
| 65 | + |
| 66 | + When using `gh auth login` interactively, the credential helper will be configured automatically. |
| 67 | + But when using `gh auth login --with-token`, as in the uv |
| 68 | + [GitHub Actions guide](../../guides/integration/github.md#private-repos), the |
| 69 | + [`gh auth setup-git`](https://cli.github.com/manual/gh_auth_setup-git) command will need to be |
| 70 | + run afterwards to configure the credential helper. |
0 commit comments