All standard Git operations are supported. Push automatically triggers code embedding for semantic search.
Basic Workflow
import { MorphClient } from '@morphllm/morphsdk';
const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY });
// Initialize
await morph.git.init({ repoId: 'my-project', dir: './my-project' });
// Clone
await morph.git.clone({ repoId: 'my-project', dir: './local-copy' });
// Stage and commit
await morph.git.add({ dir: './my-project', filepath: '.' });
await morph.git.commit({
dir: './my-project',
message: 'Add feature'
});
// Push (triggers code embedding in background)
await morph.git.push({ dir: './my-project' });
Push automatically triggers code embedding for semantic search. After 3-8 seconds, your code is searchable. Each commit is indexed separately, letting you search specific branches or historical commits.
Repository Management
Initialize Repository
await morph.git.init({
repoId: 'my-project',
dir: './my-project'
});
Initialize a new repository. The repoId uniquely identifies your project across the Morph platform.
Clone Repository
await morph.git.clone({
repoId: 'my-project',
dir: './local-copy'
});
Clone an existing repository to a new directory. Useful for multi-workspace setups or agent deployments.
Staging and Committing
Stage Changes
// Stage specific file
await morph.git.add({
dir: './my-project',
filepath: 'src/auth.ts'
});
// Stage all changes
await morph.git.add({
dir: './my-project',
filepath: '.'
});
Stage files for commit. Use . to stage all changes in the repository.
Commit Changes
await morph.git.commit({
dir: './my-project',
message: 'Implement OAuth authentication'
});
Commit staged changes with a descriptive message. See Agent Metadata for adding chat history and recordings.
Syncing Changes
Push Changes
await morph.git.push({ dir: './my-project' });
Push commits to remote. This automatically triggers code embedding in the background (3-8 seconds). Once complete, your code is searchable via Semantic Search.
Pull Changes
await morph.git.pull({ dir: './my-project' });
Pull latest changes from remote. Useful in collaborative or multi-agent environments.
Status and History
Check Status
// Simple status
const status = await morph.git.status({
dir: './my-project',
filepath: 'src/auth.ts'
});
// Detailed status matrix
const files = await morph.git.statusMatrix({ dir: './my-project' });
files.forEach(f => console.log(f.filepath, f.status));
Get file status to see what’s changed, staged, or committed.
View History
const commits = await morph.git.log({
dir: './my-project',
depth: 10
});
commits.forEach(commit => {
console.log(commit.oid, commit.commit.message);
});
View commit history. Use depth to limit how many commits are returned.
Branch Management
Create Branch
await morph.git.branch({
dir: './my-project',
name: 'feature-branch'
});
Create a new branch without checking it out.
List Branches
const branches = await morph.git.listBranches({ dir: './my-project' });
console.log('Branches:', branches);
Get all branches in the repository.
Get Current Branch
const current = await morph.git.currentBranch({ dir: './my-project' });
console.log('Current branch:', current);
Get the name of the currently checked out branch.
Checkout Branch
// Checkout existing branch
await morph.git.checkout({
dir: './my-project',
ref: 'main'
});
// Checkout specific commit
await morph.git.checkout({
dir: './my-project',
ref: 'abc123...'
});
Switch branches or checkout a specific commit.
Advanced Operations
Resolve Reference
const sha = await morph.git.resolveRef({
dir: './my-project',
ref: 'HEAD'
});
console.log('Current commit:', sha);
Get the commit hash for any reference (branch name, tag, HEAD, etc.).
Code Embedding on Push
When you push code, Morph automatically embeds it for semantic search. No vector database configuration, no embedding model management, no infrastructure setup—we handle it all.
Each commit is indexed separately, letting you:
- Search the latest code on any branch
- Search historical commits for debugging
- Compare code across different versions
// Search latest code on 'main' (default)
await morph.codebaseSearch.search({
query: "auth logic",
repoId: 'my-project'
});
// Search specific branch
await morph.codebaseSearch.search({
query: "auth logic",
repoId: 'my-project',
branch: 'develop'
});
// Search exact commit
await morph.codebaseSearch.search({
query: "auth logic",
repoId: 'my-project',
commitHash: 'abc123...'
});
See Semantic Search for full search documentation.
All Methods
| Method | Description |
|---|
init(options) | Initialize new repository |
clone(options) | Clone existing repository |
add(options) | Stage file for commit |
commit(options) | Commit staged changes |
push(options) | Push to remote (triggers code embedding) |
pull(options) | Pull from remote |
status(options) | Get file status |
statusMatrix(options) | Get all file statuses |
log(options) | Get commit history |
checkout(options) | Checkout branch or commit |
branch(options) | Create new branch |
listBranches(options) | List all branches |
currentBranch(options) | Get current branch name |
resolveRef(options) | Get commit hash for ref |
getCommitMetadata(options) | Get chat history and recording ID for a commit |