问题描述
err = worktree.Checkout(&git.Checkoutoptions{
Create: true,Branch: "main",})
if err != nil {
log.Fatal("Cannot create 'main' branch\n" + err.Error())
}
输出:
[FATA] Cannot create 'main' branch
reference not found
使用时出现相同的错误
repository.CreateBranch(&config.Branch{
Name: "main",})
解决方法
GitHub will soon rename master
to main
为真,但Git信息库的默认分支(无论是否在GitHub上)目前仍为master
。
所以先尝试:
err = worktree.Checkout(&git.CheckoutOptions{
Create: true,Branch: "master",})
但是,如果目标是创建一个新分支,请确保存储库已初始化或已签出到有效分支。
例如,请参见repository_test.go
r,_ := Init(memory.NewStorage(),nil)
testBranch := &config.Branch{
Name: "foo",Remote: "origin",Merge: "refs/heads/foo",}
err := r.CreateBranch(testBranch)