Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Create Branch? #713

@thobens

Description

@thobens

First off, there seems to be a discrepancy between https://github.com/src-d/go-git/tree/v4.0.0 and https://gopkg.in/src-d/go-git.v4. At least the file options.go is different, the one on gopkg.in is missing the CheckoutOptions.Create field.

This brings me to the question: How can one create a branch without this option?

I use this code to checkout a branch and create it if it does not exist

func createBranch(repo *git.Repository, branchName string) error {
	wt, err := repo.Worktree()
	if err != nil {
		return err
	}

	head, err := repo.Head()
	if err != nil {
		return err
	}

	var ref plumbing.ReferenceName
	ref = (plumbing.ReferenceName)("refs/heads/" + branchName)

	err = wt.Checkout(&git.CheckoutOptions{
		Branch: ref,
		Hash:   head.Hash(),
		// Create: true, <-- not available
	})

	return err
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions