-
Notifications
You must be signed in to change notification settings - Fork 898
Closed as not planned
Labels
staleIssues/PRs that are marked for closure due to inactivityIssues/PRs that are marked for closure due to inactivity
Description
I want to create a new repo and commit to new branch.
Can someone please point out what am I missing?
func main() {
InitNewRepo("git@github.com:xyz/uvw.git", // make sure repo is empty with no branches
&http.BasicAuth{
Username: "abc", // yes, this can be anything except an empty string
Password: "ghp_xxxxx",
})
}
func InitNewRepo(url string, auth *http.BasicAuth) {
repo, err := git.Init(memory.NewStorage(), memfs.New())
checkErr(err)
_, err = repo.CreateRemote(&config.RemoteConfig{
Name: "origin",
URLs: []string{url}})
checkErr(err)
worktree, err := repo.Worktree()
checkErr(err)
fmt.Println("checking out new branch")
err = worktree.Checkout(&git.CheckoutOptions{
Branch: plumbing.NewBranchReferenceName("main"),
Create: true,
})
checkErr(err)
}
func checkErr(err error) {
if err != nil {
log.Fatal(err)
}
}When executing above, I get error:
checking out new branch
2022/03/02 15:26:34 reference not found
exit status 1Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
staleIssues/PRs that are marked for closure due to inactivityIssues/PRs that are marked for closure due to inactivity