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.
resource "github_branch" "development" {
repository = "example"
branch = "development"
}
The following arguments are supported:
repository
- (Required) The GitHub repository name.
branch
- (Required) The repository branch to create.
source_branch
- (Optional) The branch name to start from. Defaults to main
.
source_sha
- (Optional) The commit hash to start from. Defaults to the tip of source_branch
. If provided, source_branch
is ignored.
The following additional attributes are exported:
source_sha
- A string storing the commit this branch was started from. Not populated when imported.
etag
- An etag representing the Branch object.
ref
- A string representing a branch reference, in the form of refs/heads/<branch>
.
sha
- A string storing the reference's HEAD
commit's SHA1.
GitHub Branch can be imported using an ID made up of repository:branch
, e.g.
$ terraform import github_branch.terraform terraform:main
Importing github branch into an instance object (when using a for each block to manage multiple branches)
$ terraform import github_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.
$ terraform import github_branch.terraform terraform:feature-branch:dev