> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Git 연동

> 액세스 토큰을 만들고, Git으로 프로젝트를 클론한 다음, pull과 push를 합니다.

Git을 사용해 내 컴퓨터에서 프로젝트를 작업하세요. 변경 사항은 `git pull` 또는 `git push`를 실행할 때만 전송됩니다.

> [!NOTE]
>
> 먼저 관리자가 [Git 연동](https://ayakaleaf-pro.mintlify.site/ko/on-premises/configuration/overleaf-toolkit/integrations/git-integration.md)을 켜야 합니다.

## 토큰 만들기

Git은 계정 비밀번호가 아니라 Git 인증 토큰으로 로그인합니다.

**1. 계정 설정 열기**

**Account**를 클릭한 다음 **Account settings**를 클릭합니다. **Git integration** 아래에서 **Generate token**을 클릭합니다. 토큰이 생기면 이 버튼은 **Add another token**으로 바뀝니다.

![Generate token 버튼이 있는 계정 설정의 Git integration 섹션](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/git-integration-settings.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=f4ff1f16eb46266f7bf31956bf3b9d89)

계정 설정의 Git 연동

**2. 토큰 복사**

**Copy**를 클릭하고 토큰을 안전한 곳에 보관합니다. 토큰은 한 번만 표시됩니다. 그런 다음 **Close**를 클릭합니다.

![Copy 버튼이 있는 Git 인증 토큰 대화 상자](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/git-integration-token.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=8358a37df6799da34fd12c6503f619f5)

새 토큰

**3. 토큰 확인**

이제 목록에 토큰의 앞부분, 생성 시각, 마지막 사용 시각이 표시됩니다. 토큰은 1년 후 만료됩니다. 토큰은 최대 10개까지 가질 수 있습니다.

![토큰이 하나 있는 토큰 목록](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/git-integration-tokens.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=e96fcc8b665f3005f950b7706fdf451c)

내 토큰

## 프로젝트 클론하기

**1. 편집기에서 Git 연동 열기**

프로젝트를 엽니다. 왼쪽 막대에서 **Integrations**를 클릭한 다음 **Git integration**을 클릭합니다.

![Git integration 카드가 있는 Integrations 패널](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/git-integration-panel.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=3fb82c63ba8d205191eadb5015bdefb5)

Integrations 패널

**2. 명령 복사**

**Clone with Git** 대화 상자에 사이트 주소와 프로젝트 ID가 포함된 명령이 표시됩니다. **Copy**를 클릭합니다. 아직 토큰이 없다면 **Go to settings**를 클릭해 새 탭에서 계정 설정을 엽니다.

![git clone 명령이 있는 Clone with Git 대화 상자](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/git-integration-clone.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=f6d69046df7caf4cbee07f49e8dd6540)

클론 명령

**3. 명령 실행**

명령을 터미널에 붙여 넣습니다. Git이 비밀번호를 요청하면 토큰을 붙여 넣습니다.

```text theme={null}
$ git clone https://git@<your-site>/git/<project-id>
Cloning into '<project-id>'...
Password for 'https://git@<your-site>': <your-token>
```

이제 프로젝트 ID 이름의 폴더에 `main` 브랜치의 프로젝트 파일이 들어 있습니다. 폴더 이름을 직접 정하려면 명령 끝에 이름을 추가하세요.

Git은 사이트에 접속할 때마다 토큰을 요청합니다. 토큰을 기억하게 하려면 credential helper를 켜세요. Git이 한 번 더 묻고 나면 토큰을 보관합니다. `store` helper는 토큰을 암호화하지 않고 `~/.git-credentials`에 저장합니다.

```bash theme={null}
git config --global credential.helper store
```

## 편집기의 변경 사항 가져오기

폴더 안에서 다음을 실행합니다.

```bash theme={null}
git pull
```

Git이 변경된 파일을 나열합니다. 편집기에서 한 변경 사항은 `Update on Overleaf.`라는 커밋으로 들어옵니다.

```text theme={null}
Updating db007e3..c3e6332
Fast-forward
 main.tex | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
```

## 변경 사항 push하기

변경 사항을 커밋한 다음 push합니다.

```bash theme={null}
git add main.tex
git commit -m "Add a line from Git"
git push
```

출력의 마지막 줄에 이동한 브랜치가 표시됩니다.

```text theme={null}
   53aca61..db007e3  main -> main
```

변경 사항이 편집기에 나타나고, 열려 있는 편집기는 자동으로 업데이트됩니다. 새 파일, 폴더, 이름 변경은 파일 트리에 표시됩니다. **History**에서는 변경 사항에 **You (via Git)**라고 표시됩니다. 커밋 메시지는 그곳에 표시되지 않습니다.

![push한 줄이 You (via Git)로 표시된 프로젝트 기록](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/git-integration-history.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=e2f4d5575612ebd75db3656cac1ea495)

프로젝트 기록의 push

### Git이 push를 거부하는 경우

그사이 프로젝트가 변경되었으면 Git이 push를 거부합니다.

```text theme={null}
 ! [rejected]        main -> main (fetch first)
```

먼저 그 변경 사항을 가져온 다음 다시 push합니다.

```bash theme={null}
git pull --no-rebase --no-edit
git push
```

일반 `git pull`은 `fatal: Need to specify how to reconcile divergent branches.`와 함께 멈출 수 있습니다. 위의 `--no-rebase` 옵션이 이를 해결하며, 양쪽을 병합합니다.

양쪽에서 같은 줄이 변경되었으면 pull이 `CONFLICT (content): Merge conflict in main.tex`와 함께 멈춥니다. 파일을 수정한 다음 실행합니다.

```bash theme={null}
git add main.tex
git commit -m "Merge the changes from the editor"
git push
```

사이트가 받아들이지 않는 것이 두 가지 있습니다.

* 다른 브랜치: `! [remote rejected] feature -> feature (wrong branch)`. `main`만 존재하므로 작업을 그곳에 push하세요.
* 강제 push: `! [remote rejected] main -> main (forced push prohibited)`. 대신 현재 `main` 위에 변경 사항을 올리세요.

### Git이 Authentication failed라고 하는 경우

```text theme={null}
remote: Enter your Git authentication token when prompted for a password.
fatal: Authentication failed for 'https://<your-site>/git/<project-id>/'
```

토큰이 잘못되었거나 삭제되었거나, 계정 비밀번호를 입력했습니다. 기존 토큰은 다시 볼 수 없으므로, 토큰이 더 이상 없다면 새 토큰을 만드세요.

## 토큰 삭제하기

**Account settings**의 **Git integration**에서 토큰 옆의 삭제 아이콘을 클릭한 다음, 대화 상자에서 **Delete**를 클릭합니다. 그 후 Git은 해당 토큰에 `Authentication failed`로 응답합니다.

![Delete Authentication token 대화 상자](https://mintcdn.com/ayakaleaf-pro/IsGnx0wnzqtV4hI8/images/on-premises/git-integration-delete-token.png?fit=max\&auto=format\&n=IsGnx0wnzqtV4hI8\&q=85\&s=1708062228778239c6465b0369614a18)

토큰 삭제

> [!NOTE]
>
> 읽기 전용 공동 작업자가 할 수 있는 일은 [Git 연동](https://ayakaleaf-pro.mintlify.site/ko/on-premises/configuration/overleaf-toolkit/integrations/git-integration.md)의 Q\&A를 참조하세요.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.