Skip to content

Error when creating a new branch for an empty repository #577

@anouarchattouna

Description

@anouarchattouna

Hello,

We are facing this error while trying to create a new branch for a new repository :

github_branch.branch: Creating...

Error: Error querying GitHub branch reference my-organization/first-repository (refs/heads/master): GET https://api.github.com/repos/my-organization/first-repository/git/refs/heads/master: 409 Git Repository is empty. []

  on main.tf line 15, in resource "github_branch" "branch":
  15: resource "github_branch" "branch" {

Terraform Version

Terraform v0.12.29
+ provider.github v2.9.2

Affected Resource(s)

  • github_branch

Terraform Configuration Files

provider "github" {
  version = "~> 2.9"
  token        = "***"
  organization = "my-organization"
}

resource "github_repository" "repository" {
  name        = "first-repository"
  description = "This is the first repository"
  private     = true

  delete_branch_on_merge = true
}

resource "github_branch" "branch" {
  repository = github_repository.repository.name
  branch     = "main"
}

Expected Behavior

Create the repository and the branch

Actual Behavior

The branch is not created because the repository is empty

Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Up for grabsIssues that are ready to be worked on by anyoneType: SupportAny questions, information, or general needs around the SDK or GitHub APIsr/branch

    Type

    No type

    Projects

    Status

    🔥 Backlog

    Status

    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions