GitHub Write File

GitHub Write File

Creates or overwrites a file in a new branch of a GitHub repository

Node Type

Action

Category

GitHub

Icon

GitHub

Overview

The GitHub Write File node is an action node that creates or overwrites files in GitHub repositories by creating a new branch from a base reference and committing the file changes. This powerful integration enables automated file management, documentation updates, and code generation workflows directly within GitHub repositories.

Key Features

  • Automated File Creation: Create or update files in GitHub repositories programmatically
  • Branch Management: Automatically creates new branches for file changes
  • Flexible Repository Input: Support for GitHub URLs or owner/repo format with dynamic selection
  • Base Reference Support: Branch from any branch, tag, or commit SHA
  • Automatic Branch Naming: Generates unique branch names with timestamps
  • File Content Management: Handles both new file creation and existing file updates
  • Comprehensive Output: Returns file content, branch name, and operation status

Prerequisites

GitHub Authentication

Must have a connected GitHub account with appropriate permissions

GitHub account connected via OAuth
Repository write access permissions for target repositories
Valid GitHub access token with repository write scope

Repository Access

Understanding of repository structure and file write requirements

Write access to the target GitHub repository
Repository must be accessible and not archived
Understanding of branch creation and file path conventions
Knowledge of base branch references (default branch if not specified)

Technical Requirements

Technical setup and configuration requirements

GitHub OAuth service properly configured
Internet connectivity for GitHub API communication
Proper exception handling for API failures and authentication issues
Branch creation and file content management capabilities

Node Configuration

Required Fields

Repository

Type:dynamic_select
Required:Yes
Value Type:string

Repository URL or owner/repo format (e.g., https://github.com/acme/tools or acme/tools). The node will automatically populate available repositories from your GitHub account.

File path

Type:text
Required:Yes
Value Type:string

Path to the file within the repository (e.g., path/to/file.txt). Use forward slashes for path separators. The file will be created or updated at this location.

Contents

Type:text_area
Required:Yes
Value Type:string

Raw contents to write to the file. This can be plain text, code, JSON, or any other file content you want to store in the repository.

Optional Fields

Base ref

Type:text
Required:No
Value Type:string

Base branch, tag, or commit SHA to branch from. If not specified, defaults to the repository's default branch (usually 'main' or 'master').

Examples & Use Cases

Documentation Updates

Automatically update documentation files in GitHub repositories

{
  "repository": "myorg/docs",
  "filePath": "api/changelog.md",
  "contents": "# API Changelog\n\n## Version 2.1.0\n- Added new authentication endpoints\n- Improved error handling\n- Updated rate limiting",
  "baseRef": "main"
}

This will create a new branch from main, update the changelog.md file with new content, and commit the changes. The file will be ready for review and merging.

Configuration File Management

Update configuration files with new settings or environment-specific values

{
  "repository": "acme/webapp",
  "filePath": "config/production.json",
  "contents": "{\n  \"database\": {\n    \"host\": \"prod-db.example.com\",\n    \"port\": 5432,\n    \"ssl\": true\n  },\n  \"api\": {\n    \"baseUrl\": \"https://api.example.com\",\n    \"timeout\": 30000\n  }\n}",
  "baseRef": "main"
}

Updates the production configuration file with new database and API settings. The changes will be committed to a new branch for review.

Automated Code Generation

Generate and commit code files based on templates or AI output

Workflow Structure

🤖 AI Code Generation → 📝 GitHub Write File → 🔍 Code Review → 🚀 Deploy

Generate code using AI, write it to GitHub, trigger code review processes, and deploy the changes automatically.

Release Notes Generation

Automatically generate and commit release notes for new versions

Workflow Structure

📊 Analyze Commits → 📝 Generate Release Notes → 📄 GitHub Write File → 🏷️ Create Tag

Analyze recent commits, generate comprehensive release notes, write them to the repository, and create version tags.

Environment-Specific Files

Create environment-specific configuration files from templates

{
  "repository": "mycompany/infrastructure",
  "filePath": "environments/staging/terraform.tfvars",
  "contents": "# Staging Environment Configuration\n\nproject_id = \"myproject-staging\"\nregion = \"us-central1\"\ninstance_type = \"n1-standard-2\"\nenvironment = \"staging\"",
  "baseRef": "main"
}

Creates environment-specific Terraform configuration files for different deployment environments, ensuring consistent infrastructure setup.

Best Practices

Do's

  • Use the dynamic repository selector to choose from available repositories
  • Specify clear and descriptive file paths that follow repository conventions
  • Include meaningful content that adds value to the repository
  • Use specific base refs (branches, tags, commits) for reproducible workflows
  • Test file content before writing to ensure it's valid and properly formatted
  • Use the success output to verify file writing operations
  • Store repository and file path information for reference in subsequent nodes
  • Consider the impact of file changes on existing code and documentation

Don'ts

  • Don't write files to repositories without proper write access
  • Avoid using incorrect file paths that might conflict with existing files
  • Don't forget to handle authentication errors gracefully
  • Avoid writing very large files that might cause performance issues
  • Don't assume repository access without verification
  • Avoid overwriting critical files without proper review processes
  • Don't write files with sensitive information like passwords or API keys
  • Avoid creating files that might conflict with existing build or deployment processes
💡
Pro Tip: The GitHub Write File node is perfect for automated documentation updates, configuration management, and code generation workflows. Always review the generated branch before merging, and consider using this node in combination with pull request creation nodes for proper code review processes.

Troubleshooting

Common Issues

Authentication Errors

Symptoms: Node fails with GitHub access token not found error

Solution: Ensure your GitHub account is properly connected via OAuth and that you have valid access tokens with repository write permissions. Check your GitHub integration settings and verify the OAuth scopes include repository write access.

Repository Not Found

Symptoms: Node fails with repository not found error

Solution: Verify the repository name is correct and that you have write access to the repository. Use the dynamic repository selector to choose from available repositories. Ensure the repository is not archived or deleted.

Invalid Base Ref

Symptoms: Node fails with invalid base ref error

Solution: Ensure the base ref (branch, tag, or commit SHA) exists in the repository. Check that the ref name is spelled correctly and that it exists in the repository history. If not specified, the node will use the default branch.

File Path Issues

Symptoms: Node fails with file path errors

Solution: Check that the file path is valid and follows GitHub conventions. Use forward slashes for path separators and avoid special characters that might cause issues. Ensure the path doesn't conflict with existing files unless you intend to overwrite them.

Branch Creation Failures

Symptoms: Node fails when creating new branches

Solution: Verify that you have permission to create branches in the repository. Check that the base ref exists and is accessible. Ensure there are no naming conflicts with existing branches.

Content Encoding Issues

Symptoms: File content appears corrupted or incorrectly encoded

Solution: Ensure the content is properly formatted and encoded. For special characters or binary content, consider using base64 encoding. Test with simple text content first to verify the node is working correctly.

API Rate Limiting

Symptoms: Node fails with rate limit exceeded error

Solution: GitHub API has rate limits. If you're making many requests, consider adding delays between requests or using GitHub's GraphQL API for more efficient operations. Monitor your API usage and implement retry logic with exponential backoff.

Related Resources