| 1 | # Server Discovery |
| 2 | |
| 3 | One of the Git LFS goals is to work with supporting Git remotes with as few |
| 4 | required configuration properties as possible. Git LFS will attempt to use |
| 5 | your Git remote to determine the LFS server. You can also configure a custom |
| 6 | LFS server if your Git remote doesn't support one, or you just want to use a |
| 7 | separate one. |
| 8 | |
| 9 | Look for the `Endpoint` properties in `git lfs env` to see your current LFS |
| 10 | servers. |
| 11 | |
| 12 | ## Guessing the Server |
| 13 | |
| 14 | By default, Git LFS will append `.git/info/lfs` to the end of a Git remote url |
| 15 | to build the LFS server URL it will use: |
| 16 | |
| 17 | Git Remote: `https://git-server.com/foo/bar`<br> |
| 18 | LFS Server: `https://git-server.com/foo/bar.git/info/lfs` |
| 19 | |
| 20 | Git Remote: `https://git-server.com/foo/bar.git`<br> |
| 21 | LFS Server: `https://git-server.com/foo/bar.git/info/lfs` |
| 22 | |
| 23 | Git Remote: `[email protected]:foo/bar.git`<br> |
| 24 | LFS Server: `https://git-server.com/foo/bar.git/info/lfs` |
| 25 | |
| 26 | Git Remote: `ssh://git-server.com/foo/bar.git`<br> |
| 27 | LFS Server: `https://git-server.com/foo/bar.git/info/lfs` |
| 28 | |
| 29 | ## SSH |
| 30 | |
| 31 | If Git LFS detects an SSH remote, it will run the `git-lfs-authenticate` |
| 32 | command. This allows supporting Git servers to give the Git LFS client |
| 33 | alternative authentication so the user does not have to setup a git credential |
| 34 | helper. |
| 35 | |
| 36 | Git LFS runs the following command: |
| 37 | |
| 38 | $ ssh [{user}@]{server} git-lfs-authenticate {path} {operation} |
| 39 | |
| 40 | The `user`, `server`, and `path` properties are taken from the SSH remote. The |
| 41 | `operation` can either be "download" or "upload". The SSH command can be |
| 42 | tweaked with the `GIT_SSH` or `GIT_SSH_COMMAND` environment variables. The |
| 43 | output for successful commands is JSON, and matches the schema as an `action` |
| 44 | in a Batch API response. Git LFS will dump the STDERR from the `ssh` command if |
| 45 | it returns a non-zero exit code. |
| 46 | |
| 47 | Examples: |
| 48 | |
| 49 | The `git-lfs-authenticate` command can even suggest an LFS endpoint that does |
| 50 | not match the Git remote by specifying an `href` property. |
| 51 | |
| 52 | ```bash |
| 53 | # Called for remotes like: |
| 54 | # * [email protected]:foo/bar.git |
| 55 | # * ssh://[email protected]/foo/bar.git |
| 56 | $ ssh [email protected] git-lfs-authenticate foo/bar.git download |
| 57 | { |
| 58 | "href": "https://lfs-server.com/foo/bar", |
| 59 | "header": { |
| 60 | "Authorization": "RemoteAuth some-token" |
| 61 | }, |
| 62 | "expires_in": 86400 |
| 63 | } |
| 64 | ``` |
| 65 | |
| 66 | Git LFS will output the STDERR if `git-lfs-authenticate` returns a non-zero |
| 67 | exit code: |
| 68 | |
| 69 | ```bash |
| 70 | $ ssh [email protected] git-lfs-authenticate foo/bar.git wat |
| 71 | Invalid LFS operation: "wat" |
| 72 | ``` |
| 73 | |
| 74 | If the `git-lfs-authenticate` command is not available on the server, Git LFS |
| 75 | treats the command as unsupported and falls back to the guessed LFS endpoint |
| 76 | described above, authenticating with the normal Git credential helper. This is |
| 77 | detected either when the remote `ssh` invocation exits with status code 127 |
| 78 | (the conventional "command not found" status) or when its output contains a |
| 79 | `git-lfs-authenticate: ... not found` message, as returned, for example, by |
| 80 | Gerrit, which exits with a generic status code. Any other non-zero exit code is |
| 81 | treated as a fatal error. |
| 82 | |
| 83 | ## Custom Configuration |
| 84 | |
| 85 | If Git LFS can't guess your LFS server, or you aren't using the |
| 86 | `git-lfs-authenticate` command, you can specify the LFS server using Git config. |
| 87 | |
| 88 | Set `lfs.url` to set the LFS server, regardless of Git remote. |
| 89 | |
| 90 | ```bash |
| 91 | $ git config lfs.url https://lfs-server.com/foo/bar |
| 92 | ``` |
| 93 | |
| 94 | You can set `remote.{name}.lfsurl` to set the LFS server for that specific |
| 95 | remote only: |
| 96 | |
| 97 | ```bash |
| 98 | $ git config remote.dev.lfsurl http://lfs-server.dev/foo/bar |
| 99 | $ git lfs env |
| 100 | ... |
| 101 | |
| 102 | Endpoint=https://git-server.com/foo/bar.git/info/lfs (auth=none) |
| 103 | Endpoint (dev)=http://lfs-server.dev/foo/bar (auth=none) |
| 104 | ``` |
| 105 | |
| 106 | Git LFS will also read these settings from a `.lfsconfig` file in the root of |
| 107 | your repository. This lets you commit it to the repository so that all users |
| 108 | can use it, if you wish. |
| 109 | |
| 110 | ```bash |
| 111 | $ git config --file=.lfsconfig lfs.url https://lfs-server.com/foo/bar |
| 112 | ``` |