> ## 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/ja/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 個まで持てます。

![トークンが 1 つあるトークンの一覧](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
```

サイトが受け付けないものが 2 つあります。

* 他のブランチ: `! [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/ja/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.