When i try to use worktree checkout; it doesn't work and the code returns error
err = worktree.Checkout(&git.CheckoutOptions{
Create: true,
Branch: "main",
})
if err != nil {
log.Fatal("Cannot create 'main' branch\n" + err.Error())
}
Output:
[FATA] Cannot create 'main' branch
reference not found
I get the same error when i use
repository.CreateBranch(&config.Branch{
Name: "main",
})
While it is true GitHub will soon rename
master
tomain
, the default branch for a Git repository (on GitHub or not) is stillmaster
for now.So try first:
But if the goal is to create a new branch, make sure the repo is either initialized or already checked out to a valid branch.
For example, see
repository_test.go
The OP capsci adds in the comments: