Rasa X version 0.33.0 or higher is only compatible with Rasa Open Source 2.x. If you are on Rasa Open Source 1.x, please check the [compatibility matrix](https://legacy-docs-rasa-x.rasa.com/docs/rasa-x/changelog/compatibility-matrix) for a compatible version.

If you want to use self-generated SSH keys or prefer to use the Rasa X API for any other reason, you can also use the [Rasa X HTTP API](https://legacy-docs-rasa-x.rasa.com/docs/rasa-x/pages/http-api) to connect Rasa X to your Git repository.

##### caution

When connecting the Rasa X instance to a git repository, **any training data or configuration files** stored in Rasa X will be overwritten by those in the Git repository. If you were using Rasa X to manage your assistant before setting up Integrated Version Control, be sure to download the data before continuing, so that the data is not lost. You can push the downloaded data from your machine to your Git repo before or after connecting it to Rasa X.

## Using SSH to Authenticate

1. To authenticate your Rasa X server with the remote repository via SSH, you need to set up an SSH key that Rasa X can use for authentication. Please **create a new, single-use SSH key** for this (see instructions below). Also, make sure to restrict the SSH keys to only apply to your assistant’s repository.

To generate a new SSH key pair follow these steps:

1. Open the Terminal

2. Execute the following command (make sure to not overwrite your own SSH keys):

```bash
ssh-keygen -t rsa -b 4096 -f git-deploy-key
```

This provides you a private (`git-deploy-key`) and a public (`git-deploy-key.pub`) key in your current directory.

##### note

Please note that Rasa X currently does not support password protected private keys.

2. Save your repository information and private key to a file `repository.json`, in the format shown below. If your Rasa X server does not use HTTPS, we highly recommend doing this directly on your server to avoid compromising the key. As the contents of this file will uploaded via a curl request, the directory where it is stored does not matter, but it is recommended to store the file somewhere secure.

```json
{
  "repository_url":"<your repository's SSH clone url>",
  "target_branch":"<the default branch Rasa X will use>",
  "ssh_key":"<your generated private SSH key>",
  "is_target_branch_protected":false
}
```

##### note

The **target branch** is the branch that Rasa X will...

- use to show the initial data
  - branch off from when you make new changes
  - return to after you discard or push changes

If you want to disable adding changes directly to the target branch, please specify `is_target_branch_protected": true/false` in the `repository.json` file.

For example, your `repository.json` might look like:

```json
{
  "repository_url":"git@github.com:RasaHQ/rasa-demo.git",
  "target_branch":"main",
  "ssh_key":"-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn\nNhAAAAAwEAAQAAAgEAu/Giin7t8DFMxsaTbyy1To2EQpLIAhpAIgpyC/e45NYVTwKRGCB1\nmxHzt5IWoh7GSWry3pKFBM74UpXxrRPBdCmFeUIiJoslAukNkRSckAUj0VEfOIZLf2SSPg\n......................................................................\nCDHniFksE1SjkAAAEBANJacZeM2Qdk/vditmBQV97Ac2VJL/Btt8Rks2Vb3CORyXQn3Bpb\n+5ZONhmPEoCg4FcZbAm02gYw3dSoBBWz2i8mmAv71mVsNoddWKpDngRFv4PUaITnYYxrZ4\n-----END OPENSSH PRIVATE KEY-----"
}
```

3. To authenticate with the Rasa X server you can use one of two methods:
   - **API token authentication**: Get your API token by going to the Models screen in Rasa X and clicking the `Upload Model` button in the upper right-hand corner. Copy the `api_token` token from the upload command. Similar to in this command, you will add it to the curl command shown below with the `api_token` query parameter.
   - **JWT token authentication**: Use your JWT access token. You can get it from the [authentication](https://legacy-docs-rasa-x.rasa.com/docs/rasa-x/pages/http-api#tag/Authentication) endpoint and pass it within the `Authorization` header.

Once you have prepared your chosen form of authentication, create the repository by executing the following HTTP request from the directory that contains your `repository.json`:

```bash
# with API token authentication
curl --request POST \
  --url http://<Rasa X server host>/api/git-repositories?api_token=<your api token> \
  --header 'Content-Type: application/json' \
  --data-binary @repository.json
```

```bash
# with JWT token authentication
curl --request POST \
  --url http://<Rasa X server host>/api/git-repositories \
  --header 'Authorization: Bearer <your access token>' \
  --header 'Content-Type: application/json' \
  --data-binary @repository.json
```

##### note

If your Rasa X server runs on HTTPS, make sure to use `https://` in the `--url` parameter.

## Using HTTPS to Authenticate

##### note

Connecting to remote repositories via HTTPS is only possible with **Rasa Enterprise**.

1. To authenticate your Rasa X server with the remote repository via HTTPS, you need the necessary credentials to access the repository: username and password. If your account has 2FA (Two-Factor Authentication) enabled, you will need to create a personal access token that allows you to access the repository, and use that as a password.

2. Use the Rasa X API to create the repository, using either **API token authentication** or **JWT token authentication**:

```bash
# with API token authentication
curl --request POST \
  --url http://<Rasa X server host>/api/git-repositories?api_token=<your api token> \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "repository_url": "<your repository HTTPS clone URL>",
    "target_branch": "<the default branch Rasa X will use>",
    "is_target_branch_protected": false,
    "username": "<your username>",
    "password": "<your password or personal access token>"
}'
```

```bash
# with JWT token authentication
curl --request POST \
  --url http://<Rasa X server host>/api/git-repositories \
  --header 'Authorization: Bearer <your access token>' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "repository_url": "<your repository HTTPS clone URL>",
    "target_branch": "<the default branch Rasa X will use>",
    "is_target_branch_protected": false,
    "username": "<your username>",
    "password": "<your password or personal access token>"
}'
```
