What is the canonical way to push specific single local branch to specific remote with 100?
我签出了一个本地存储库,并以go-git
英镑打开
repo, err := git.PlainOpen("my-repo")
回购的默认设置为origin
Remote.
我正在try 将此存储库的内容同步到另一个遥控器mirror
,因此我正在添加遥控器
repo.CreateRemote(&config.RemoteConfig{
Name: "mirror",
URLs: []string{"git@github.com:foo/mirror.git"},
})
首先,我从origin
中获取回购内容
err = remote.Fetch(&git.FetchOptions{
RemoteName: "origin",
Tags: git.AllTags,
})
...并使用remote.List()
查找所有感兴趣的分支和标记
最后一步是将分支推到mirror
,同时根据映射重写分支名称.例如,签出的refs/remotes/origin/master
AS refs/heads/master
应推送到mirror
远程AS main
.因此,我迭代遍历分支,并try 逐个推送它们:
refSpec := config.RefSpec(fmt.Sprintf(
"+%s:refs/remotes/mirror/%s",
localBranch.Name().String(),
// map branch names, e.g. master -> main
mapBranch(remoteBranch.Name().Short()),
))
err = repo.Push(&git.PushOptions{
RemoteName: "mirror",
Force: true,
RefSpecs: []config.RefSpec{refSpec},
Atomic: true,
})
但结果是git.NoErrAlreadyUpToDate
,而mirror
遥控器上什么也没有发生.