# gitignore 的 REST API 端点

使用 REST API 获取可用于忽略文件和目录的 .gitignore 模板。

## 关于 gitignore

通过 API 在 GitHub 上创建新存储库时，可以指定一个 [.gitignore 模板](/zh/enterprise-server@3.20/get-started/git-basics/ignoring-files)在创建后应用于存储库。 可以使用 REST API 从 GitHub [.gitignore 存储库](https://github.com/github/gitignore)中获取 .gitignore 模板。

> \[!NOTE]
> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2022-11-28`. Curl examples below omit these standard headers for brevity.

## Get all gitignore templates

```
GET /gitignore/templates
```

List all templates available to pass as an option when creating a repository.

### HTTP response status codes

* **200** - OK

* **304** - Not modified

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/gitignore/templates
```

**Response schema (Status: 200):**

Array of string

## Get a gitignore template

```
GET /gitignore/templates/{name}
```

Get the content of a gitignore template.
This endpoint supports the following custom media types. For more information, see "Media types."

application/vnd.github.raw+json: Returns the raw .gitignore contents.

### Parameters

#### Headers

* **`accept`** (string)
  Setting to `application/vnd.github+json` is recommended.

#### Path and query parameters

* **`name`** (string) (required)

### HTTP response status codes

* **200** - OK

* **304** - Not modified

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/gitignore/templates/NAME
```

**Response schema (Status: 200):**

* `name`: required, string
* `source`: required, string