npm package: @ionah-tools/ina-cli
Description: Sync or create branch across multiple Git repos - for microservices workflow
Author: ionah
Latest version: 1.1.2

# ina-cli

Sync or create branches across multiple Git repos – for microservices workflow.

## Requirements

- **Node.js** >= 14.0.0
- **npm** (included with Node.js)
- **Git**

## Installation

Works on **Windows**, **macOS**, and **Linux**.

```bash
npm i -g @ionah-tools/ina-cli
```

## Upgrade

```bash
npm i -g @ionah-tools/ina-cli
```

Check version: `ina -v` or `ina version`

## Initial setup

**Set your workspace** – the parent directory containing your microservices (each microservice = one subfolder/repo):

```bash
# Show current workspace
ina set

# Point to workspace (Windows)
ina set C:\projects

# Point to workspace (Mac/Linux)
ina set ~/projects
```

**First time** using `ina start` or `ina live` without a workspace set → you'll be **prompted to enter** the workspace path.

## Usage

```bash
# ina start: lists repos, prompts to select by number (e.g. 1 2 3 or all)
ina start feature/IO-1234  

# ina live: discard all changes, checkout pico, fetch & pull latest
ina live
```

### `ina start <branch-name>`

For each selected repo:

1. **Skip** if uncommitted changes (commit or stash first)
2. **Skip** if branch `pico` does not exist (remote or local)
3. `fetch origin`
4. Checkout `pico`: if local exists → `checkout pico`, else → `checkout -b pico origin/pico`
5. `pull origin pico`
6. If target branch exists → checkout & pull. Else → `checkout -b` (create local only)

### `ina live`

For each selected repo:

1. **Skip** if branch `pico` does not exist (remote or local)
2. `reset --hard` + `clean -fd` (discard all changes)
3. `fetch origin`
4. Checkout `pico`: if local exists → `checkout pico`, else → `checkout -b pico origin/pico`
5. `pull origin pico`

**Note:** Both commands operate locally only. No `git push` to remote.

## .ina-repos file in parent directory

Create `.ina-repos` (or `.pico-repos`, `.sync-repos`) in the parent directory:

```
frontend
api
user-service
# order-service
```

## Example directory structure

```
C:\projects\   ← ina set C:\projects (workspace)
├── frontend/      ← microservice 1
├── api/           ← microservice 2
├── user-service/  ← microservice 3
└── .ina-repos
```

## Commands

| Command | Description |
|---------|-------------|
| `ina set` | Show current workspace |
| `ina set <path>` | Point to workspace (parent dir containing microservices) |
| `ina start <branch>` | Create branch from pico (interactive repo selection) |
| `ina live` | Discard changes, checkout pico, fetch & pull |
| `ina version`, `ina -v` | Show version |

## Help

Run `ina` (no arguments) to show full usage:

```
  ina - Sync/create branch across multiple Git repos

  Usage:
    ina start <branch-name>        Create branch from pico (interactive repo selection)
    ina live                       Discard changes, checkout pico, fetch & pull
    ina set [path]                 Point to workspace (parent dir containing microservices)
    ina version, ina -v            Show version

  Examples:
    ina start feature/IO-1234      List repos → select by number → create branch from pico
    ina set                        Show current workspace
    ina set C:/projects            Point to C:/projects (containing frontend, api, ...)
    ina set ~/projects
    ina live                       Discard changes → checkout pico → fetch & pull

  First-time start/live when no workspace set → prompts for path.
  Base branch: pico. Skips repos with uncommitted changes or no pico branch.

  Upgrade: npm i -g @ionah-tools/ina-cli
```

## License

MIT