LogoFreestyle
Advanced

Git Contents API

Access and explore Git repository data.

Accessing Repository Contents

Get File or Directory Contents

Retrieve the contents of a file or directory at a specific ref (branch, commit, tag):

const response = await fetch(
  `https://api.freestyle.sh/git/v1/repo/${repoId}/contents/${filePath}?ref=${ref}`,
  {
    headers: {
      Authorization: `Bearer ${apiKey}`,
    },
  }
);
const contents = await response.json();

The response includes file content (base64-encoded) or directory listings with recursive entries.

Download Archives

Download repository contents as compressed archives:

# Download as tar
curl -H "Authorization: Bearer ${apiKey}" \
  "https://api.freestyle.sh/git/v1/repo/${repoId}/tarball?ref=${ref}" \
  -o repo.tar

# Download as zip
curl -H "Authorization: Bearer ${apiKey}" \
  "https://api.freestyle.sh/git/v1/repo/${repoId}/zip?ref=${ref}" \
  -o repo.zip

References

Get branch and tag references:

// Get branch reference
const branchRef = await fetch(
  `https://api.freestyle.sh/git/v1/repo/${repoId}/git/refs/heads/${branchName}`,
  {
    headers: { Authorization: `Bearer ${apiKey}` },
  }
).then(r => r.json());

// Get tag reference
const tagRef = await fetch(
  `https://api.freestyle.sh/git/v1/repo/${repoId}/git/refs/tags/${tagName}`,
  {
    headers: { Authorization: `Bearer ${apiKey}` },
  }
).then(r => r.json());

Default Branch

Get or set the repository's default branch:

// Get default branch
const { defaultBranch } = await fetch(
  `https://api.freestyle.sh/git/v1/repo/${repoId}/default-branch`,
  {
    headers: { Authorization: `Bearer ${apiKey}` },
  }
).then(r => r.json());

// Set default branch
await fetch(
  `https://api.freestyle.sh/git/v1/repo/${repoId}/default-branch`,
  {
    method: 'PUT',
    headers: {
      Authorization: `Bearer ${apiKey}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ defaultBranch: 'main' }),
  }
);

Git Database API

For advanced use cases requiring direct access to Git objects (blobs, trees, commits, tags), see the Git Objects API guide.

On this page

Freestyle AI

Documentation assistant

Experimental: AI responses may not always be accurate—please verify important details with the official documentation.

How can I help?

Ask me about Freestyle while you browse the docs.