github logo
GitHub v5.6.0, Mar 14 23

github.Branch

This resource allows you to create and manage branches within your repository.

Additional constraints can be applied to ensure your branch is created from another branch or commit.

Example Usage

using System.Collections.Generic;
using Pulumi;
using Github = Pulumi.Github;

return await Deployment.RunAsync(() => 
{
    var development = new Github.Branch("development", new()
    {
        BranchName = "development",
        Repository = "example",
    });

});
package main

import (
	"github.com/pulumi/pulumi-github/sdk/v5/go/github"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := github.NewBranch(ctx, "development", &github.BranchArgs{
			Branch:     pulumi.String("development"),
			Repository: pulumi.String("example"),
		})
		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.Branch;
import com.pulumi.github.BranchArgs;
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 development = new Branch("development", BranchArgs.builder()        
            .branch("development")
            .repository("example")
            .build());

    }
}
import pulumi
import pulumi_github as github

development = github.Branch("development",
    branch="development",
    repository="example")
import * as pulumi from "@pulumi/pulumi";
import * as github from "@pulumi/github";

const development = new github.Branch("development", {
    branch: "development",
    repository: "example",
});
resources:
  development:
    type: github:Branch
    properties:
      branch: development
      repository: example

Create Branch Resource

new Branch(name: string, args: BranchArgs, opts?: CustomResourceOptions);
@overload
def Branch(resource_name: str,
           opts: Optional[ResourceOptions] = None,
           branch: Optional[str] = None,
           repository: Optional[str] = None,
           source_branch: Optional[str] = None,
           source_sha: Optional[str] = None)
@overload
def Branch(resource_name: str,
           args: BranchArgs,
           opts: Optional[ResourceOptions] = None)
func NewBranch(ctx *Context, name string, args BranchArgs, opts ...ResourceOption) (*Branch, error)
public Branch(string name, BranchArgs args, CustomResourceOptions? opts = null)
public Branch(String name, BranchArgs args)
public Branch(String name, BranchArgs args, CustomResourceOptions options)
type: github:Branch
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args BranchArgs
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 BranchArgs
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 BranchArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args BranchArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args BranchArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Branch Resource Properties

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

Inputs

The Branch resource accepts the following input properties:

BranchName string

The repository branch to create.

Repository string

The GitHub repository name.

SourceBranch string

The branch name to start from. Defaults to main.

SourceSha string

The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.

Branch string

The repository branch to create.

Repository string

The GitHub repository name.

SourceBranch string

The branch name to start from. Defaults to main.

SourceSha string

The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.

branch String

The repository branch to create.

repository String

The GitHub repository name.

sourceBranch String

The branch name to start from. Defaults to main.

sourceSha String

The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.

branch string

The repository branch to create.

repository string

The GitHub repository name.

sourceBranch string

The branch name to start from. Defaults to main.

sourceSha string

The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.

branch str

The repository branch to create.

repository str

The GitHub repository name.

source_branch str

The branch name to start from. Defaults to main.

source_sha str

The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.

branch String

The repository branch to create.

repository String

The GitHub repository name.

sourceBranch String

The branch name to start from. Defaults to main.

sourceSha String

The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.

Outputs

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

Etag string

An etag representing the Branch object.

Id string

The provider-assigned unique ID for this managed resource.

Ref string

A string representing a branch reference, in the form of refs/heads/<branch>.

Sha string

A string storing the reference's HEAD commit's SHA1.

Etag string

An etag representing the Branch object.

Id string

The provider-assigned unique ID for this managed resource.

Ref string

A string representing a branch reference, in the form of refs/heads/<branch>.

Sha string

A string storing the reference's HEAD commit's SHA1.

etag String

An etag representing the Branch object.

id String

The provider-assigned unique ID for this managed resource.

ref String

A string representing a branch reference, in the form of refs/heads/<branch>.

sha String

A string storing the reference's HEAD commit's SHA1.

etag string

An etag representing the Branch object.

id string

The provider-assigned unique ID for this managed resource.

ref string

A string representing a branch reference, in the form of refs/heads/<branch>.

sha string

A string storing the reference's HEAD commit's SHA1.

etag str

An etag representing the Branch object.

id str

The provider-assigned unique ID for this managed resource.

ref str

A string representing a branch reference, in the form of refs/heads/<branch>.

sha str

A string storing the reference's HEAD commit's SHA1.

etag String

An etag representing the Branch object.

id String

The provider-assigned unique ID for this managed resource.

ref String

A string representing a branch reference, in the form of refs/heads/<branch>.

sha String

A string storing the reference's HEAD commit's SHA1.

Look up Existing Branch Resource

Get an existing Branch 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?: BranchState, opts?: CustomResourceOptions): Branch
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        branch: Optional[str] = None,
        etag: Optional[str] = None,
        ref: Optional[str] = None,
        repository: Optional[str] = None,
        sha: Optional[str] = None,
        source_branch: Optional[str] = None,
        source_sha: Optional[str] = None) -> Branch
func GetBranch(ctx *Context, name string, id IDInput, state *BranchState, opts ...ResourceOption) (*Branch, error)
public static Branch Get(string name, Input<string> id, BranchState? state, CustomResourceOptions? opts = null)
public static Branch get(String name, Output<String> id, BranchState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
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:
BranchName string

The repository branch to create.

Etag string

An etag representing the Branch object.

Ref string

A string representing a branch reference, in the form of refs/heads/<branch>.

Repository string

The GitHub repository name.

Sha string

A string storing the reference's HEAD commit's SHA1.

SourceBranch string

The branch name to start from. Defaults to main.

SourceSha string

The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.

Branch string

The repository branch to create.

Etag string

An etag representing the Branch object.

Ref string

A string representing a branch reference, in the form of refs/heads/<branch>.

Repository string

The GitHub repository name.

Sha string

A string storing the reference's HEAD commit's SHA1.

SourceBranch string

The branch name to start from. Defaults to main.

SourceSha string

The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.

branch String

The repository branch to create.

etag String

An etag representing the Branch object.

ref String

A string representing a branch reference, in the form of refs/heads/<branch>.

repository String

The GitHub repository name.

sha String

A string storing the reference's HEAD commit's SHA1.

sourceBranch String

The branch name to start from. Defaults to main.

sourceSha String

The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.

branch string

The repository branch to create.

etag string

An etag representing the Branch object.

ref string

A string representing a branch reference, in the form of refs/heads/<branch>.

repository string

The GitHub repository name.

sha string

A string storing the reference's HEAD commit's SHA1.

sourceBranch string

The branch name to start from. Defaults to main.

sourceSha string

The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.

branch str

The repository branch to create.

etag str

An etag representing the Branch object.

ref str

A string representing a branch reference, in the form of refs/heads/<branch>.

repository str

The GitHub repository name.

sha str

A string storing the reference's HEAD commit's SHA1.

source_branch str

The branch name to start from. Defaults to main.

source_sha str

The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.

branch String

The repository branch to create.

etag String

An etag representing the Branch object.

ref String

A string representing a branch reference, in the form of refs/heads/<branch>.

repository String

The GitHub repository name.

sha String

A string storing the reference's HEAD commit's SHA1.

sourceBranch String

The branch name to start from. Defaults to main.

sourceSha String

The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.

Import

GitHub Branch can be imported using an ID made up of repository:branch, e.g.

 $ pulumi import github:index/branch:Branch terraform terraform:main

Importing github branch into an instance object (when using a for each block to manage multiple branches)

 $ pulumi import github:index/branch:Branch terraform["terraform"] terraform:main

Optionally, a source branch may be specified using an ID of repository:branch:source_branch. This is useful for importing branches that do not branch directly off main.

 $ pulumi import github:index/branch:Branch terraform terraform:feature-branch:dev

Package Details

Repository
GitHub pulumi/pulumi-github
License
Apache-2.0
Notes

This Pulumi package is based on the github Terraform Provider.