src-d / go-git

Project has been moved to: https://github.com/go-git/go-git
https://github.com/go-git/go-git
Apache License 2.0
4.91k stars 541 forks source link

How to create a new repo programmatically #1280

Open rjdsd opened 4 years ago

rjdsd commented 4 years ago

I am trying to create a new Repo through this API on bitbucket

Following is the pseudocode

       newRepoURL :=  "ssh://git@ourbitbucket:port/myproject/myApp.git"
       r, err := git.PlainInit(newRepoURL, false)
       w, err := r.Worktree()
       filename := filepath.Join(newRepoURL, "example-git-file")
       _, err = w.Add("example-git-file")
       commit, err := w.Commit("init commit to new repo", &git.CommitOptions{
                                 Auth : auth
                                 }
        remote, err := r.CreateRemote(&config.RemoteConfig{
            Name: "myApp",
            URLs: []string{newRepoURL},
                 })
        err = remote.Push(&git.PushOptions{
            RemoteName: "myApp",
            Auth:auth,
                 }) 

But I get following error

unknown error: Repository not found

Could anyone help where I am going wrong here.