Git Commit Downloader

API Documentation

Overview

Our API allows you to download GitHub repositories as ZIP files programmatically. This is useful for automation, CI/CD pipelines, or any scenario where you need to fetch repository content without using Git commands.

Endpoint

GET /api/zip

Parameters

ParameterRequiredDescription
urlYesThe GitHub repository URL (e.g., https://github.com/owner/repo)
commitNoThe commit SHA to download. If not provided, the latest commit from the default branch will be used.
tokenNoGitHub personal access token with repo scope. Required for private repositories.

Response

The API returns a ZIP file as an attachment with the repository contents.

Headers:

Content-Type: application/zipContent-Disposition: attachment; filename="repo-commit.zip"

Examples

Basic Usage

Download the latest commit from a public repository:

https://git-downloader.com/api/zip?url=https://github.com/facebook/react

Specific Commit

Download a specific commit:

https://git-downloader.com/api/zip?url=https://github.com/facebook/react&commit=0cf22a4cd5b5b947d06a63867419c3f26a967984

Private Repository

Download from a private repository using a token:

https://git-downloader.com/api/zip?url=https://github.com/owner/private-repo&token=ghp_your_personal_access_token

Error Responses

Status CodeDescription
400Missing or invalid parameters
401Authentication failed (invalid token)
403Rate limit exceeded or insufficient permissions
404Repository or commit not found
500Internal server error

Code Examples

JavaScript (Fetch)

// Download and save a repository as a zip file
async function downloadRepo() {
  const url = 'https://git-downloader.com/api/zip?url=https://github.com/owner/repo';
  
  try {
    const response = await fetch(url);
    
    if (!response.ok) {
      throw new Error(`Error: ${response.status} ${response.statusText}`);
    }
    
    // Get the filename from the Content-Disposition header
    const contentDisposition = response.headers.get('content-disposition');
    const filename = contentDisposition
      ? contentDisposition.split('filename=')[1].replace(/"/g, '')
      : 'repository.zip';
    
    // Convert the response to a blob
    const blob = await response.blob();
    
    // Create a download link and trigger the download
    const downloadUrl = window.URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = downloadUrl;
    a.download = filename;
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
    window.URL.revokeObjectURL(downloadUrl);
  } catch (error) {
    console.error('Download failed:', error);
  }
}

Python

import requests
import os

def download_repository(github_url, commit=None, token=None):
    """
    Download a GitHub repository as a zip file
    
    Args:
        github_url (str): GitHub repository URL
        commit (str, optional): Commit SHA
        token (str, optional): GitHub personal access token
    """
    # Construct the API URL
    api_url = 'https://git-downloader.com/api/zip'
    params = {'url': github_url}
    
    if commit:
        params['commit'] = commit
    
    if token:
        params['token'] = token
    
    try:
        # Make the request
        response = requests.get(api_url, params=params, stream=True)
        response.raise_for_status()
        
        # Get filename from Content-Disposition header
        content_disposition = response.headers.get('content-disposition', '')
        if 'filename=' in content_disposition:
            filename = content_disposition.split('filename=')[1].strip('"')
        else:
            # Extract repo name from GitHub URL
            repo_name = github_url.rstrip('/').split('/')[-1]
            filename = f"{repo_name}.zip"
        
        # Save the file
        with open(filename, 'wb') as f:
            for chunk in response.iter_content(chunk_size=8192):
                f.write(chunk)
        
        print(f"Repository downloaded successfully as {filename}")
        return filename
    
    except requests.exceptions.RequestException as e:
        print(f"Error downloading repository: {e}")
        return None

# Example usage
download_repository('https://github.com/owner/repo')