1. Packages
  2. Packages
  3. Github Provider
  4. API Docs
  5. RepositoryFile
Viewing docs for GitHub v4.17.0 (Older version)
published on Monday, Mar 9, 2026 by Pulumi
github logo
Viewing docs for GitHub v4.17.0 (Older version)
published on Monday, Mar 9, 2026 by Pulumi

    This resource allows you to create and manage files within a GitHub repository.

    Example Usage

    using System.Collections.Generic;
    using Pulumi;
    using Github = Pulumi.Github;
    
    return await Deployment.RunAsync(() => 
    {
        var fooRepository = new Github.Repository("fooRepository", new()
        {
            AutoInit = true,
        });
    
        var fooRepositoryFile = new Github.RepositoryFile("fooRepositoryFile", new()
        {
            Repository = fooRepository.Name,
            Branch = "main",
            File = ".gitignore",
            Content = "**/*.tfstate",
            CommitMessage = "Managed by Terraform",
            CommitAuthor = "Terraform User",
            CommitEmail = "terraform@example.com",
            OverwriteOnCreate = true,
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-github/sdk/v4/go/github"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		fooRepository, err := github.NewRepository(ctx, "fooRepository", &github.RepositoryArgs{
    			AutoInit: pulumi.Bool(true),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = github.NewRepositoryFile(ctx, "fooRepositoryFile", &github.RepositoryFileArgs{
    			Repository:        fooRepository.Name,
    			Branch:            pulumi.String("main"),
    			File:              pulumi.String(".gitignore"),
    			Content:           pulumi.String("**/*.tfstate"),
    			CommitMessage:     pulumi.String("Managed by Terraform"),
    			CommitAuthor:      pulumi.String("Terraform User"),
    			CommitEmail:       pulumi.String("terraform@example.com"),
    			OverwriteOnCreate: pulumi.Bool(true),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.github.Repository;
    import com.pulumi.github.RepositoryArgs;
    import com.pulumi.github.RepositoryFile;
    import com.pulumi.github.RepositoryFileArgs;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Map;
    import java.io.File;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    
    public class App {
        public static void main(String[] args) {
            Pulumi.run(App::stack);
        }
    
        public static void stack(Context ctx) {
            var fooRepository = new Repository("fooRepository", RepositoryArgs.builder()        
                .autoInit(true)
                .build());
    
            var fooRepositoryFile = new RepositoryFile("fooRepositoryFile", RepositoryFileArgs.builder()        
                .repository(fooRepository.name())
                .branch("main")
                .file(".gitignore")
                .content("**/*.tfstate")
                .commitMessage("Managed by Terraform")
                .commitAuthor("Terraform User")
                .commitEmail("terraform@example.com")
                .overwriteOnCreate(true)
                .build());
    
        }
    }
    
    import * as pulumi from "@pulumi/pulumi";
    import * as github from "@pulumi/github";
    
    const fooRepository = new github.Repository("fooRepository", {autoInit: true});
    const fooRepositoryFile = new github.RepositoryFile("fooRepositoryFile", {
        repository: fooRepository.name,
        branch: "main",
        file: ".gitignore",
        content: "**/*.tfstate",
        commitMessage: "Managed by Terraform",
        commitAuthor: "Terraform User",
        commitEmail: "terraform@example.com",
        overwriteOnCreate: true,
    });
    
    import pulumi
    import pulumi_github as github
    
    foo_repository = github.Repository("fooRepository", auto_init=True)
    foo_repository_file = github.RepositoryFile("fooRepositoryFile",
        repository=foo_repository.name,
        branch="main",
        file=".gitignore",
        content="**/*.tfstate",
        commit_message="Managed by Terraform",
        commit_author="Terraform User",
        commit_email="terraform@example.com",
        overwrite_on_create=True)
    
    resources:
      fooRepository:
        type: github:Repository
        properties:
          autoInit: true
      fooRepositoryFile:
        type: github:RepositoryFile
        properties:
          repository: ${fooRepository.name}
          branch: main
          file: .gitignore
          content: '**/*.tfstate'
          commitMessage: Managed by Terraform
          commitAuthor: Terraform User
          commitEmail: terraform@example.com
          overwriteOnCreate: true
    

    Create RepositoryFile Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new RepositoryFile(name: string, args: RepositoryFileArgs, opts?: CustomResourceOptions);
    @overload
    def RepositoryFile(resource_name: str,
                       args: RepositoryFileArgs,
                       opts: Optional[ResourceOptions] = None)
    
    @overload
    def RepositoryFile(resource_name: str,
                       opts: Optional[ResourceOptions] = None,
                       content: Optional[str] = None,
                       file: Optional[str] = None,
                       repository: Optional[str] = None,
                       branch: Optional[str] = None,
                       commit_author: Optional[str] = None,
                       commit_email: Optional[str] = None,
                       commit_message: Optional[str] = None,
                       overwrite_on_create: Optional[bool] = None)
    func NewRepositoryFile(ctx *Context, name string, args RepositoryFileArgs, opts ...ResourceOption) (*RepositoryFile, error)
    public RepositoryFile(string name, RepositoryFileArgs args, CustomResourceOptions? opts = null)
    public RepositoryFile(String name, RepositoryFileArgs args)
    public RepositoryFile(String name, RepositoryFileArgs args, CustomResourceOptions options)
    
    type: github:RepositoryFile
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args RepositoryFileArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args RepositoryFileArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args RepositoryFileArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args RepositoryFileArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args RepositoryFileArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var repositoryFileResource = new Github.RepositoryFile("repositoryFileResource", new()
    {
        Content = "string",
        File = "string",
        Repository = "string",
        Branch = "string",
        CommitAuthor = "string",
        CommitEmail = "string",
        CommitMessage = "string",
        OverwriteOnCreate = false,
    });
    
    example, err := github.NewRepositoryFile(ctx, "repositoryFileResource", &github.RepositoryFileArgs{
    	Content:           pulumi.String("string"),
    	File:              pulumi.String("string"),
    	Repository:        pulumi.String("string"),
    	Branch:            pulumi.String("string"),
    	CommitAuthor:      pulumi.String("string"),
    	CommitEmail:       pulumi.String("string"),
    	CommitMessage:     pulumi.String("string"),
    	OverwriteOnCreate: pulumi.Bool(false),
    })
    
    var repositoryFileResource = new RepositoryFile("repositoryFileResource", RepositoryFileArgs.builder()
        .content("string")
        .file("string")
        .repository("string")
        .branch("string")
        .commitAuthor("string")
        .commitEmail("string")
        .commitMessage("string")
        .overwriteOnCreate(false)
        .build());
    
    repository_file_resource = github.RepositoryFile("repositoryFileResource",
        content="string",
        file="string",
        repository="string",
        branch="string",
        commit_author="string",
        commit_email="string",
        commit_message="string",
        overwrite_on_create=False)
    
    const repositoryFileResource = new github.RepositoryFile("repositoryFileResource", {
        content: "string",
        file: "string",
        repository: "string",
        branch: "string",
        commitAuthor: "string",
        commitEmail: "string",
        commitMessage: "string",
        overwriteOnCreate: false,
    });
    
    type: github:RepositoryFile
    properties:
        branch: string
        commitAuthor: string
        commitEmail: string
        commitMessage: string
        content: string
        file: string
        overwriteOnCreate: false
        repository: string
    

    RepositoryFile Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    The RepositoryFile resource accepts the following input properties:

    Content string
    The file content.
    File string
    The path of the file to manage.
    Repository string
    The repository to create the file in.
    Branch string
    Git branch (defaults to main). The branch must already exist, it will not be created if it does not already exist.
    CommitAuthor string
    Committer author name to use.
    CommitEmail string
    Committer email address to use.
    CommitMessage string
    Commit message when adding or updating the managed file.
    OverwriteOnCreate bool
    Enable overwriting existing files
    Content string
    The file content.
    File string
    The path of the file to manage.
    Repository string
    The repository to create the file in.
    Branch string
    Git branch (defaults to main). The branch must already exist, it will not be created if it does not already exist.
    CommitAuthor string
    Committer author name to use.
    CommitEmail string
    Committer email address to use.
    CommitMessage string
    Commit message when adding or updating the managed file.
    OverwriteOnCreate bool
    Enable overwriting existing files
    content String
    The file content.
    file String
    The path of the file to manage.
    repository String
    The repository to create the file in.
    branch String
    Git branch (defaults to main). The branch must already exist, it will not be created if it does not already exist.
    commitAuthor String
    Committer author name to use.
    commitEmail String
    Committer email address to use.
    commitMessage String
    Commit message when adding or updating the managed file.
    overwriteOnCreate Boolean
    Enable overwriting existing files
    content string
    The file content.
    file string
    The path of the file to manage.
    repository string
    The repository to create the file in.
    branch string
    Git branch (defaults to main). The branch must already exist, it will not be created if it does not already exist.
    commitAuthor string
    Committer author name to use.
    commitEmail string
    Committer email address to use.
    commitMessage string
    Commit message when adding or updating the managed file.
    overwriteOnCreate boolean
    Enable overwriting existing files
    content str
    The file content.
    file str
    The path of the file to manage.
    repository str
    The repository to create the file in.
    branch str
    Git branch (defaults to main). The branch must already exist, it will not be created if it does not already exist.
    commit_author str
    Committer author name to use.
    commit_email str
    Committer email address to use.
    commit_message str
    Commit message when adding or updating the managed file.
    overwrite_on_create bool
    Enable overwriting existing files
    content String
    The file content.
    file String
    The path of the file to manage.
    repository String
    The repository to create the file in.
    branch String
    Git branch (defaults to main). The branch must already exist, it will not be created if it does not already exist.
    commitAuthor String
    Committer author name to use.
    commitEmail String
    Committer email address to use.
    commitMessage String
    Commit message when adding or updating the managed file.
    overwriteOnCreate Boolean
    Enable overwriting existing files

    Outputs

    All input properties are implicitly available as output properties. Additionally, the RepositoryFile resource produces the following output properties:

    CommitSha string
    The SHA of the commit that modified the file.
    Id string
    The provider-assigned unique ID for this managed resource.
    Sha string
    The SHA blob of the file.
    CommitSha string
    The SHA of the commit that modified the file.
    Id string
    The provider-assigned unique ID for this managed resource.
    Sha string
    The SHA blob of the file.
    commitSha String
    The SHA of the commit that modified the file.
    id String
    The provider-assigned unique ID for this managed resource.
    sha String
    The SHA blob of the file.
    commitSha string
    The SHA of the commit that modified the file.
    id string
    The provider-assigned unique ID for this managed resource.
    sha string
    The SHA blob of the file.
    commit_sha str
    The SHA of the commit that modified the file.
    id str
    The provider-assigned unique ID for this managed resource.
    sha str
    The SHA blob of the file.
    commitSha String
    The SHA of the commit that modified the file.
    id String
    The provider-assigned unique ID for this managed resource.
    sha String
    The SHA blob of the file.

    Look up Existing RepositoryFile Resource

    Get an existing RepositoryFile resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: RepositoryFileState, opts?: CustomResourceOptions): RepositoryFile
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            branch: Optional[str] = None,
            commit_author: Optional[str] = None,
            commit_email: Optional[str] = None,
            commit_message: Optional[str] = None,
            commit_sha: Optional[str] = None,
            content: Optional[str] = None,
            file: Optional[str] = None,
            overwrite_on_create: Optional[bool] = None,
            repository: Optional[str] = None,
            sha: Optional[str] = None) -> RepositoryFile
    func GetRepositoryFile(ctx *Context, name string, id IDInput, state *RepositoryFileState, opts ...ResourceOption) (*RepositoryFile, error)
    public static RepositoryFile Get(string name, Input<string> id, RepositoryFileState? state, CustomResourceOptions? opts = null)
    public static RepositoryFile get(String name, Output<String> id, RepositoryFileState state, CustomResourceOptions options)
    resources:  _:    type: github:RepositoryFile    get:      id: ${id}
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    Branch string
    Git branch (defaults to main). The branch must already exist, it will not be created if it does not already exist.
    CommitAuthor string
    Committer author name to use.
    CommitEmail string
    Committer email address to use.
    CommitMessage string
    Commit message when adding or updating the managed file.
    CommitSha string
    The SHA of the commit that modified the file.
    Content string
    The file content.
    File string
    The path of the file to manage.
    OverwriteOnCreate bool
    Enable overwriting existing files
    Repository string
    The repository to create the file in.
    Sha string
    The SHA blob of the file.
    Branch string
    Git branch (defaults to main). The branch must already exist, it will not be created if it does not already exist.
    CommitAuthor string
    Committer author name to use.
    CommitEmail string
    Committer email address to use.
    CommitMessage string
    Commit message when adding or updating the managed file.
    CommitSha string
    The SHA of the commit that modified the file.
    Content string
    The file content.
    File string
    The path of the file to manage.
    OverwriteOnCreate bool
    Enable overwriting existing files
    Repository string
    The repository to create the file in.
    Sha string
    The SHA blob of the file.
    branch String
    Git branch (defaults to main). The branch must already exist, it will not be created if it does not already exist.
    commitAuthor String
    Committer author name to use.
    commitEmail String
    Committer email address to use.
    commitMessage String
    Commit message when adding or updating the managed file.
    commitSha String
    The SHA of the commit that modified the file.
    content String
    The file content.
    file String
    The path of the file to manage.
    overwriteOnCreate Boolean
    Enable overwriting existing files
    repository String
    The repository to create the file in.
    sha String
    The SHA blob of the file.
    branch string
    Git branch (defaults to main). The branch must already exist, it will not be created if it does not already exist.
    commitAuthor string
    Committer author name to use.
    commitEmail string
    Committer email address to use.
    commitMessage string
    Commit message when adding or updating the managed file.
    commitSha string
    The SHA of the commit that modified the file.
    content string
    The file content.
    file string
    The path of the file to manage.
    overwriteOnCreate boolean
    Enable overwriting existing files
    repository string
    The repository to create the file in.
    sha string
    The SHA blob of the file.
    branch str
    Git branch (defaults to main). The branch must already exist, it will not be created if it does not already exist.
    commit_author str
    Committer author name to use.
    commit_email str
    Committer email address to use.
    commit_message str
    Commit message when adding or updating the managed file.
    commit_sha str
    The SHA of the commit that modified the file.
    content str
    The file content.
    file str
    The path of the file to manage.
    overwrite_on_create bool
    Enable overwriting existing files
    repository str
    The repository to create the file in.
    sha str
    The SHA blob of the file.
    branch String
    Git branch (defaults to main). The branch must already exist, it will not be created if it does not already exist.
    commitAuthor String
    Committer author name to use.
    commitEmail String
    Committer email address to use.
    commitMessage String
    Commit message when adding or updating the managed file.
    commitSha String
    The SHA of the commit that modified the file.
    content String
    The file content.
    file String
    The path of the file to manage.
    overwriteOnCreate Boolean
    Enable overwriting existing files
    repository String
    The repository to create the file in.
    sha String
    The SHA blob of the file.

    Import

    Repository files can be imported using a combination of the repo and file, e.g.

     $ pulumi import github:index/repositoryFile:RepositoryFile gitignore example/.gitignore
    

    To import a file from a branch other than main, append : and the branch name, e.g.

     $ pulumi import github:index/repositoryFile:RepositoryFile gitignore example/.gitignore:dev
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    GitHub pulumi/pulumi-github
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the github Terraform Provider.
    github logo
    Viewing docs for GitHub v4.17.0 (Older version)
    published on Monday, Mar 9, 2026 by Pulumi
      Try Pulumi Cloud free. Your team will thank you.