Skip to main content
The fastest way to get up and running is with the Code Storage SDK, available for both TypeScript and Python. Before getting started head to the dashboard to generate a private key and make note of your organization’s name identifier.
  1. Install the SDK:
    pnpm i @pierre/storage
    
  2. Initialize the client:
    import { GitStorage } from '@pierre/storage';
    
    const store = new GitStorage({
      name: 'your-org', // Your organization identifier
      key: env.privateKey, // Your API key
    });
    
  3. Create and use a repository:
    // Create a new repository
    const repo = await store.createRepo();
    
    // Get a secure Git URL with authentication
    const url = await repo.getRemoteURL();
    
    // Configure Git to use the repository
    console.log(`git remote add origin ${url}`);
    // Output: git remote add origin https://t:JWT@[org].code.storage/repo-id.git
    
  4. Make your first commit:
    import { GitStorage } from '@pierre/storage';
    
    async function main() {
      const store = new GitStorage({
        name: 'your-name',
        key: env.privateKey,
      });
    
      const repo = await store.createRepo();
      console.log(`Created repository: ${repo.id}`);
    
      const url = await repo.getRemoteURL();
      console.log(`Git URL: ${url}`);
    
      const result = await repo
        .createCommit({
          targetBranch: 'main',
          commitMessage: 'Initial commit',
          author: { name: 'Your Name', email: 'you@example.com' },
        })
        .addFileFromString('README.md', '# My Project\n\nWelcome!')
        .send();
    
      console.log(`Commit SHA: ${result.commitSha}`);
    }
    
  5. Read repository data:
    async function readData() {
      const store = new GitStorage({ name: 'your-name', key: env.privateKey });
      const repo = await store.findOne({ id: 'repo-id' });
    
      if (!repo) return;
    
      // List files
      const files = await repo.listFiles();
      console.log('Files:', files.paths);
    
      // List commits
      const commits = await repo.listCommits({ limit: 10 });
      commits.commits.forEach((commit) => {
        console.log(`${commit.sha.slice(0, 7)} - ${commit.message}`);
      });
    
      // Get file content
      const response = await repo.getFileStream({ path: 'README.md' });
      const content = await response.text();
      console.log(content);
    }
    
  6. Apply an existing diff:
    async function applyDiff() {
      const store = new GitStorage({ name: 'your-name', key: env.privateKey });
      const repo = await store.findOne({ id: 'repo-id' });
    
      if (!repo) return;
    
      const diffText = `--- a/README.md
    +++ b/README.md
    @@
    -Old line
    +New line
    `;
    
      const result = await repo.createCommitFromDiff({
        targetBranch: 'main',
        commitMessage: 'Apply upstream changes',
        diff: diffText,
        author: { name: 'Automation', email: 'bot@example.com' },
        baseBranch: 'main', // optional, matches createCommit options
      });
    
      console.log(`Updated commit: ${result.commitSha}`);
    }