> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getnao.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Git Repository Setup

> Turn your local context folder into a GitHub repository

Convert your local nao project into a Git repository for version control, collaboration, and automated deployments.

## Why Use Git?

Using Git for your nao project provides:

* **Version Control**: Track changes to your context files
* **Collaboration**: Multiple team members can contribute
* **Automated Sync**: Use GitHub Actions to automatically sync context
* **Deployment**: Easy integration with cloud deployments (Cloud Run, etc.)
* **Backup**: Your context is safely stored in the cloud

## Initial Setup

### Step 1: Initialize Git Repository

Navigate to your nao project directory:

```bash theme={null}
cd your-nao-project
```

Initialize a Git repository:

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

### Step 2: Create .gitignore

Create a `.gitignore` file to exclude sensitive files:

```gitignore theme={null}
# Environment variables
.env

# Credentials (never commit these!)
credentials/

# Python
venv/
```

<Warning>
  **Never commit credentials or API keys to Git!** Always use environment variables or secret management systems.
</Warning>

### Step 3: Configure for Git

Update your `nao_config.yaml` to use environment variables instead of file paths:

**Before (local files):**

```yaml theme={null}
databases:
  - name: bigquery-prod
    type: bigquery
    project_id: my-project
    dataset_id: analytics
    credentials_path: /path/to/credentials/key-file.json
```

**After (environment variables):**

```yaml theme={null}
databases:
  - name: bigquery-prod
    type: bigquery
    project_id: my-project
    dataset_id: analytics
    credentials_json: {{ env('GCP_SERVICE_ACCOUNT_KEY_JSON') }}
```

### Step 4: Add and Commit Files

Add your project files:

```bash theme={null}
git add .
git commit -m "Initial nao project"
```

### Step 5: Create GitHub Repository

1. Go to [GitHub](https://github.com) and create a new repository
2. **Don't** initialize with README, .gitignore, or license (you already have these)
3. Copy the repository URL

### Step 6: Connect to GitHub

Add the remote and push:

```bash theme={null}
git remote add origin https://github.com/your-username/your-repo.git
git branch -M main
git push -u origin main
```

## Best Practices

**1. Use Environment Variables**

Always use environment variables for secrets:

```yaml theme={null}
# ✅ Good
credentials_json: {{ env('GCP_SERVICE_ACCOUNT_KEY_JSON') }}
api_key: ${OPENAI_API_KEY}

# ❌ Bad - Never do this
credentials_path: ./credentials/key.json
api_key: sk-abc123...
```

**2. Store Secrets Securely**

**For Local Development:**

* Use `.env` file (in `.gitignore`)
* Load with `source .env` or a tool like `direnv`

**For Cloud Deployments:**

* Use secret management (Google Secret Manager, AWS Secrets Manager, etc.)
* Store in GitHub Secrets for Actions

**For GitHub Actions:**

* Go to repository Settings → Secrets and variables → Actions
* Add secrets for all credentials used in `nao_config.yaml`

**3. Commit Synced Context**

After running `nao sync`, commit the generated context files:

```bash theme={null}
nao sync
git add databases/ docs/ repos/
git commit -m "Update context from nao sync"
git push
```

**4. Use Automated Sync**

Set up [GitHub Actions](/nao-agent/context-builder/synchronization#github-actions) to automatically sync and commit context updates.

## Deployment Integration

**Cloud Run Deployment**

When deploying to Cloud Run:

1. Connect your GitHub repository to Cloud Build
2. Cloud Build automatically builds and deploys on push
3. Use Secret Manager for credentials
4. Environment variables are set in Cloud Run configuration

See the [Self-Hosting Guide](/nao-agent/self-hosting/deployment-guide#3-deploy-nao-to-google-cloud-run) for Cloud Run deployment details.

**Dockerfile**

Create a `Dockerfile` in your repository:

```dockerfile theme={null}
FROM getnao/nao:latest

# Copy your project
COPY . /app/project/

# Set working directory
WORKDIR /app/project
```

Create a `.dockerignore`:

```
.env
venv/
.git/
.gitignore
credentials/
```

**What's Next?**

<CardGroup cols={2}>
  <Card title="Synchronization" icon="sync" href="/nao-agent/context-builder/synchronization">
    Set up automated syncing with GitHub Actions
  </Card>

  <Card title="Self-Hosting Guide" icon="docker" href="/nao-agent/self-hosting/deployment-guide">
    Deploy your repository to production (local Docker & Cloud Run)
  </Card>
</CardGroup>
