@morphllm/morph-git-sdk TypeScript SDK.
GitMorph (Client)
The main client. Handles authentication and provides access to repositories.Constructor Options
| Option | Type | Description |
|---|---|---|
token | string | API token. Falls back to GM_TOKEN env, then ~/.config/gm/config.json |
host | string | Server hostname. Falls back to GM_HOST env, then gitmorph.com |
repo(slug)
Returns a GitMorphRepo handle for the given repository.
getRepositoryInfo(slug)
Fetch metadata for a repository.
Repository object.
mirror(source, options?)
Mirror a repository from GitHub, GitLab, or another Gitea instance.
| Option | Type | Default | Description |
|---|---|---|---|
source | "github" | "gitlab" | "gitea" | auto-detect | Source platform |
repoName | string | original name | Override the destination repo name |
private | boolean | false | Make the mirrored repo private |
wiki | boolean | false | Mirror wiki |
issues | boolean | false | Mirror issues |
pullRequests | boolean | false | Mirror pull requests |
releases | boolean | false | Mirror releases |
labels | boolean | false | Mirror labels |
milestones | boolean | false | Mirror milestones |
lfs | boolean | false | Mirror LFS objects |
{ repository: Repository, repo: GitMorphRepo }.
grepAll(options)
Search code across all accessible repositories.
| Option | Type | Description |
|---|---|---|
pattern | string | Search pattern (required) |
language | string | Filter by programming language |
page | number | Page number for pagination |
limit | number | Max results per page (max 50) |
sortByStars | boolean | Sort repositories by star count |
{ matches: GrepAllMatch[], total: number }.
GitMorphRepo
Per-repository operations. Obtained viagm.repo("owner/name").
readFile(path, options?)
Read a file from the repository. Optionally read only specific line ranges.
| Option | Type | Description |
|---|---|---|
ref | string | Branch, tag, or commit SHA. Defaults to the repo’s default branch |
lines | LineRange[] | Array of { start, end } ranges (1-indexed, inclusive) |
{ path, content, totalLines, lines? }.
grep(options)
Search code within the repository using server-side search.
| Option | Type | Description |
|---|---|---|
pattern | string | Search pattern (required) |
language | string | Filter by programming language |
caseSensitive | boolean | Case-sensitive matching (default false) |
maxMatches | number | Max results (max 50) |
page | number | Page number for pagination |
{ matches: GrepMatch[], total: number }.
Each GrepMatch contains:
path- file pathlineNumber- line numberlineContent- the matching line (plain text)submatches- array of{ match, startOffset, endOffset }within the line
getFileContents(paths, options?)
Batch-read multiple files in a single request.
FileContentEntry | null (null for files that don’t exist). Content is automatically decoded from base64.
glob(options)
Find files matching glob patterns.
| Option | Type | Description |
|---|---|---|
patterns | string[] | Doublestar glob patterns (required) |
ref | string | Branch, tag, or commit SHA |
prefix | string | Directory prefix to narrow the search |
sizes | boolean | Include file sizes (default true). Set false for faster responses |
limit | number | Max results (default 1000) |
{ entries: TreeEntry[], truncated: boolean }.
listDir(options?)
List directory contents.
| Option | Type | Description |
|---|---|---|
path | string | Directory path |
ref | string | Branch, tag, or commit SHA |
recursive | boolean | Include subdirectories recursively |
{ entries: ListDirEntry[], truncated: boolean }.
listBranches(options?)
List repository branches.
Branch[] with name, commit, and protected fields.
listCommits(options?)
List commits with optional filters.
| Option | Type | Description |
|---|---|---|
sha | string | Branch name or SHA to list from |
path | string | Only commits affecting this file/directory |
since | string | ISO 8601 date, commits after this date |
until | string | ISO 8601 date, commits before this date |
page | number | Page number |
limit | number | Results per page |
Error Handling
The SDK throws typed errors for different failure modes:| Error Class | When |
|---|---|
AuthenticationError | No token found in constructor, env, or config |
ApiError | Server returned a non-2xx response (includes status and url) |
MirrorError | Mirror operation failed |
GrepError | Code search failed or invalid pattern |
GitMorphError | Base class for all SDK errors |
Types
Repository
User
CLI Reference
Thegm CLI covers repositories, issues, PRs, releases, workflows, secrets, and more. It follows the same patterns as GitHub’s gh CLI.
Repositories
Issues
Pull Requests
Code Search
Workflows & Runs
Releases
Secrets & Variables
Raw API
Configuration
Config is stored at~/.config/gm/config.json (or $GM_CONFIG_DIR/config.json).