Skip to content

Commit 6132112

Browse files
committed
Auto merge of #7658 - ehuss:doc-git-authentication, r=alexcrichton
Docs: Add an appendix on git authentication. This adds a short section on how to set up authentication with git. People seem to occasionally have difficulty with setting it up, so the hope is that this might provide some guidance, and a place for people to get started. I'm not sure if it will actually be helpful, though.
2 parents 76cdf93 + 5d9eff3 commit 6132112

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

src/doc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@
7272

7373
* [FAQ](faq.md)
7474
* [Appendix: Glossary](appendix/glossary.md)
75+
* [Appendix: Git Authentication](appendix/git-authentication.md)
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Git Authentication
2+
3+
Cargo supports some forms of authentication when using git dependencies and
4+
registries. This appendix contains some information for setting up git
5+
authentication in a way that works with Cargo.
6+
7+
If you need other authentication methods, the [`net.git-fetch-with-cli`]
8+
config value can be set to cause Cargo to execute the `git` executable to
9+
handle fetching remote repositories instead of using the built-in support.
10+
This can be enabled with the `CARGO_NET_GIT_FETCH_WITH_CLI=true` environment
11+
variable.
12+
13+
## HTTPS authentication
14+
15+
HTTPS authentication requires the [`credential.helper`] mechanism. There are
16+
multiple credential helpers, and you specify the one you want to use in your
17+
global git configuration file.
18+
19+
```ini
20+
# ~/.gitconfig
21+
22+
[credential]
23+
helper = store
24+
```
25+
26+
Cargo does not ask for passwords, so for most helpers you will need to give
27+
the helper the initial username/password before running Cargo. One way to do
28+
this is to run `git clone` of the private git repo and enter the
29+
username/password.
30+
31+
> **Tip:**<br>
32+
> macOS users may want to consider using the osxkeychain helper.<br>
33+
> Windows users may want to consider using the [GCM] helper.
34+
35+
> **Note:** Windows users will need to make sure that the `sh` shell is
36+
> available in your `PATH`. This typically is available with the Git for
37+
> Windows installation.
38+
39+
## SSH authentication
40+
41+
SSH authentication requires `ssh-agent` to be running to acquire the SSH key.
42+
Make sure the appropriate environment variables are set up (`SSH_AUTH_SOCK` on
43+
most Unix-like systems), and that the correct keys are added (with `ssh-add`).
44+
Windows uses Pageant for SSH authentication.
45+
46+
> **Note:** Cargo does not support git's shorthand SSH URLs like
47+
> `git@example.com/user/repo.git`. Use a full SSH URL like
48+
> `ssh://git@example.com/user/repo.git`.
49+
>
50+
> **Note:** SSH configuration files (like OpenSSH's `~/.ssh/config`) are not
51+
> used by Cargo's built-in SSH library. More advanced requirements should use
52+
> [`net.git-fetch-with-cli`].
53+
54+
[`credential.helper`]: https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage
55+
[`net.git-fetch-with-cli`]: ../reference/config.md#netgit-fetch-with-cli
56+
[GCM]: https://github.com/Microsoft/Git-Credential-Manager-for-Windows/

src/doc/src/reference/config.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,9 @@ indexes and git dependencies. If `false`, then it uses a built-in `git`
538538
library.
539539

540540
Setting this to `true` can be helpful if you have special authentication
541-
requirements that Cargo does not support.
541+
requirements that Cargo does not support. See [Git
542+
Authentication](../appendix/git-authentication.md) for more information about
543+
setting up git authentication.
542544

543545
##### `net.offline`
544546
* Type: boolean

src/doc/src/reference/specifying-dependencies.md

+4
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ the latest commit on a branch named `next`:
142142
rand = { git = "https://github.com/rust-lang-nursery/rand", branch = "next" }
143143
```
144144

145+
See [Git Authentication] for help with git authentication for private repos.
146+
147+
[Git Authentication]: ../appendix/git-authentication.md
148+
145149
### Specifying path dependencies
146150

147151
Over time, our `hello_world` package from [the guide](../guide/index.md) has

0 commit comments

Comments
 (0)