1. Packages
  2. Github Provider
  3. API Docs
  4. Branch
GitHub v6.7.0 published on Friday, Feb 28, 2025 by Pulumi

github.Branch

Explore with Pulumi AI

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

import * as pulumi from "@pulumi/pulumi";
import * as github from "@pulumi/github";

const development = new github.Branch("development", {
    repository: "example",
    branch: "development",
});
Copy
import pulumi
import pulumi_github as github

development = github.Branch("development",
    repository="example",
    branch="development")
Copy
package main

import (
	"github.com/pulumi/pulumi-github/sdk/v6/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{
			Repository: pulumi.String("example"),
			Branch:     pulumi.String("development"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Github = Pulumi.Github;

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

});
Copy
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()
            .repository("example")
            .branch("development")
            .build());

    }
}
Copy
resources:
  development:
    type: github:Branch
    properties:
      repository: example
      branch: development
Copy

Create Branch Resource

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

Constructor syntax

new Branch(name: string, args: BranchArgs, opts?: CustomResourceOptions);
@overload
def Branch(resource_name: str,
           args: BranchArgs,
           opts: Optional[ResourceOptions] = None)

@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)
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.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. BranchArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. 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 This property is required. string
The unique name of the resource.
args This property is required. BranchArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. BranchArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. BranchArgs
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 branchResource = new Github.Branch("branchResource", new()
{
    BranchName = "string",
    Repository = "string",
    SourceBranch = "string",
    SourceSha = "string",
});
Copy
example, err := github.NewBranch(ctx, "branchResource", &github.BranchArgs{
	Branch:       pulumi.String("string"),
	Repository:   pulumi.String("string"),
	SourceBranch: pulumi.String("string"),
	SourceSha:    pulumi.String("string"),
})
Copy
var branchResource = new Branch("branchResource", BranchArgs.builder()
    .branch("string")
    .repository("string")
    .sourceBranch("string")
    .sourceSha("string")
    .build());
Copy
branch_resource = github.Branch("branchResource",
    branch="string",
    repository="string",
    source_branch="string",
    source_sha="string")
Copy
const branchResource = new github.Branch("branchResource", {
    branch: "string",
    repository: "string",
    sourceBranch: "string",
    sourceSha: "string",
});
Copy
type: github:Branch
properties:
    branch: string
    repository: string
    sourceBranch: string
    sourceSha: string
Copy

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

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

The Branch resource accepts the following input properties:

BranchName
This property is required.
Changes to this property will trigger replacement.
string
The repository branch to create.
Repository
This property is required.
Changes to this property will trigger replacement.
string
The GitHub repository name.
SourceBranch Changes to this property will trigger replacement. string
The branch name to start from. Defaults to main.
SourceSha Changes to this property will trigger replacement. string
The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.
Branch
This property is required.
Changes to this property will trigger replacement.
string
The repository branch to create.
Repository
This property is required.
Changes to this property will trigger replacement.
string
The GitHub repository name.
SourceBranch Changes to this property will trigger replacement. string
The branch name to start from. Defaults to main.
SourceSha Changes to this property will trigger replacement. string
The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.
branch
This property is required.
Changes to this property will trigger replacement.
String
The repository branch to create.
repository
This property is required.
Changes to this property will trigger replacement.
String
The GitHub repository name.
sourceBranch Changes to this property will trigger replacement. String
The branch name to start from. Defaults to main.
sourceSha Changes to this property will trigger replacement. String
The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.
branch
This property is required.
Changes to this property will trigger replacement.
string
The repository branch to create.
repository
This property is required.
Changes to this property will trigger replacement.
string
The GitHub repository name.
sourceBranch Changes to this property will trigger replacement. string
The branch name to start from. Defaults to main.
sourceSha Changes to this property will trigger replacement. string
The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.
branch
This property is required.
Changes to this property will trigger replacement.
str
The repository branch to create.
repository
This property is required.
Changes to this property will trigger replacement.
str
The GitHub repository name.
source_branch Changes to this property will trigger replacement. str
The branch name to start from. Defaults to main.
source_sha Changes to this property will trigger replacement. str
The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.
branch
This property is required.
Changes to this property will trigger replacement.
String
The repository branch to create.
repository
This property is required.
Changes to this property will trigger replacement.
String
The GitHub repository name.
sourceBranch Changes to this property will trigger replacement. String
The branch name to start from. Defaults to main.
sourceSha Changes to this property will trigger replacement. 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)
resources:  _:    type: github:Branch    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 This property is required.
The unique name of the resulting resource.
id This property is required.
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 Changes to this property will trigger replacement. 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 Changes to this property will trigger replacement. string
The GitHub repository name.
Sha string
A string storing the reference's HEAD commit's SHA1.
SourceBranch Changes to this property will trigger replacement. string
The branch name to start from. Defaults to main.
SourceSha Changes to this property will trigger replacement. string
The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.
Branch Changes to this property will trigger replacement. 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 Changes to this property will trigger replacement. string
The GitHub repository name.
Sha string
A string storing the reference's HEAD commit's SHA1.
SourceBranch Changes to this property will trigger replacement. string
The branch name to start from. Defaults to main.
SourceSha Changes to this property will trigger replacement. string
The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.
branch Changes to this property will trigger replacement. 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 Changes to this property will trigger replacement. String
The GitHub repository name.
sha String
A string storing the reference's HEAD commit's SHA1.
sourceBranch Changes to this property will trigger replacement. String
The branch name to start from. Defaults to main.
sourceSha Changes to this property will trigger replacement. String
The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.
branch Changes to this property will trigger replacement. 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 Changes to this property will trigger replacement. string
The GitHub repository name.
sha string
A string storing the reference's HEAD commit's SHA1.
sourceBranch Changes to this property will trigger replacement. string
The branch name to start from. Defaults to main.
sourceSha Changes to this property will trigger replacement. string
The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.
branch Changes to this property will trigger replacement. 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 Changes to this property will trigger replacement. str
The GitHub repository name.
sha str
A string storing the reference's HEAD commit's SHA1.
source_branch Changes to this property will trigger replacement. str
The branch name to start from. Defaults to main.
source_sha Changes to this property will trigger replacement. str
The commit hash to start from. Defaults to the tip of source_branch. If provided, source_branch is ignored.
branch Changes to this property will trigger replacement. 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 Changes to this property will trigger replacement. String
The GitHub repository name.
sha String
A string storing the reference's HEAD commit's SHA1.
sourceBranch Changes to this property will trigger replacement. String
The branch name to start from. Defaults to main.
sourceSha Changes to this property will trigger replacement. 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
Copy

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
Copy

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
Copy

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.