# Git 참조에 대한 REST API 엔드포인트

REST API를 사용하여 GitHub에서 Git 데이터베이스 참조와 상호 작용

## Git 참조 정보

Git 참조(`git ref`)는 Git 커밋 SHA-1 해시를 포함하는 파일입니다. Git 커밋을 참조할 때 해시가 아닌 기억하기 쉬운 이름을 나타내는 Git 참조를 사용할 수 있습니다. 새 커밋을 가리키도록 Git 참조를 다시 작성할 수 있습니다. Git 분기는 새로운 Git 커밋 해시를 저장하는 참조입니다. 이러한 엔드포인트를 사용하면 GitHub에서 Git 데이터베이스에 [참조](https://git-scm.com/book/en/v2/Git-Internals-Git-References)를 읽고 쓸 수 있습니다.

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

## List matching references

```
GET /repos/{owner}/{repo}/git/matching-refs/{ref}
```

Returns an array of references from your Git database that match the supplied name. The :ref in the URL must be formatted as heads/<branch name> for branches and tags/<tag name> for tags. If the :ref doesn't exist in the repository, but existing refs start with :ref, they will be returned as an array.
When you use this endpoint without providing a :ref, it will return an array of all the references from your Git database, including notes and stashes if they exist on the server. Anything in the namespace is returned, not just heads and tags.
Note

You need to explicitly request a pull request to trigger a test merge commit, which checks the mergeability of pull requests. For more information, see "Checking mergeability of pull requests".

If you request matching references for a branch named feature but the branch feature doesn't exist, the response can still include other matching head refs that start with the word feature, such as featureA and featureB.

### Parameters

#### Headers

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

#### Path and query parameters

- **`owner`** (string) (required)
  The account owner of the repository. The name is not case sensitive.

- **`repo`** (string) (required)
  The name of the repository without the .git extension. The name is not case sensitive.

- **`ref`** (string) (required)
  The Git reference. For more information, see "Git References" in the Git documentation.

### HTTP response status codes

- **200** - OK

- **409** - Conflict

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/matching-refs/REF
```

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

Array of `Git Reference`:
  * `ref`: required, string
  * `node_id`: required, string
  * `url`: required, string, format: uri
  * `object`: required, object:
    * `type`: required, string
    * `sha`: required, string, minLength: 40, maxLength: 40
    * `url`: required, string, format: uri

## Get a reference

```
GET /repos/{owner}/{repo}/git/ref/{ref}
```

Returns a single reference from your Git database. The :ref in the URL must be formatted as heads/<branch name> for branches and tags/<tag name> for tags. If the :ref doesn't match an existing ref, a 404 is returned.
Note

You need to explicitly request a pull request to trigger a test merge commit, which checks the mergeability of pull requests. For more information, see "Checking mergeability of pull requests".

### Parameters

#### Headers

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

#### Path and query parameters

- **`owner`** (string) (required)
  The account owner of the repository. The name is not case sensitive.

- **`repo`** (string) (required)
  The name of the repository without the .git extension. The name is not case sensitive.

- **`ref`** (string) (required)
  The Git reference. For more information, see "Git References" in the Git documentation.

### HTTP response status codes

- **200** - OK

- **404** - Resource not found

- **409** - Conflict

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X GET \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/ref/REF
```

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

* `ref`: required, string
* `node_id`: required, string
* `url`: required, string, format: uri
* `object`: required, object:
  * `type`: required, string
  * `sha`: required, string, minLength: 40, maxLength: 40
  * `url`: required, string, format: uri

## Create a reference

```
POST /repos/{owner}/{repo}/git/refs
```

Creates a reference for your repository. You are unable to create new references for empty repositories, even if the commit SHA-1 hash used exists. Empty repositories are repositories without branches.

### Parameters

#### Headers

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

#### Path and query parameters

- **`owner`** (string) (required)
  The account owner of the repository. The name is not case sensitive.

- **`repo`** (string) (required)
  The name of the repository without the .git extension. The name is not case sensitive.

#### Body parameters

- **`ref`** (string) (required)
  The name of the fully qualified reference (ie: refs/heads/master). If it doesn't start with 'refs' and have at least two slashes, it will be rejected.

- **`sha`** (string) (required)
  The SHA1 value for this reference.

### HTTP response status codes

- **201** - Created

- **409** - Conflict

- **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X POST \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/refs \
  -d '{
  "ref": "refs/heads/featureA",
  "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd"
}'
```

**Response schema (Status: 201):**

Same response schema as [Get a reference](#get-a-reference).

## Update a reference

```
PATCH /repos/{owner}/{repo}/git/refs/{ref}
```

Updates the provided reference to point to a new SHA. For more information, see "Git References" in the Git documentation.

### Parameters

#### Headers

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

#### Path and query parameters

- **`owner`** (string) (required)
  The account owner of the repository. The name is not case sensitive.

- **`repo`** (string) (required)
  The name of the repository without the .git extension. The name is not case sensitive.

- **`ref`** (string) (required)
  The Git reference. For more information, see "Git References" in the Git documentation.

#### Body parameters

- **`sha`** (string) (required)
  The SHA1 value to set this reference to

- **`force`** (boolean)
  Indicates whether to force the update or to make sure the update is a fast-forward update. Leaving this out or setting it to false will make sure you're not overwriting work.
  Default: `false`

### HTTP response status codes

- **200** - OK

- **409** - Conflict

- **422** - Validation failed, or the endpoint has been spammed.

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X PATCH \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/refs/REF \
  -d '{
  "sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
  "force": true
}'
```

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

Same response schema as [Get a reference](#get-a-reference).

## Delete a reference

```
DELETE /repos/{owner}/{repo}/git/refs/{ref}
```

Deletes the provided reference.

### Parameters

#### Headers

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

#### Path and query parameters

- **`owner`** (string) (required)
  The account owner of the repository. The name is not case sensitive.

- **`repo`** (string) (required)
  The name of the repository without the .git extension. The name is not case sensitive.

- **`ref`** (string) (required)
  The Git reference. For more information, see "Git References" in the Git documentation.

### HTTP response status codes

- **204** - No Content

- **409** - Conflict

- **422** - Validation failed, an attempt was made to delete the default branch, or the endpoint has been spammed.

### Code examples

#### Example

**Request:**

```curl
curl -L \
  -X DELETE \
  http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/git/refs/REF
```

**Response schema (Status: 204):**