Git别名错误:dst ref refs / heads / feature从多个src接收

时间:2014-06-23 23:41:31

标签: git github push alias

我正在尝试创建一个自动初始化和发布新分支的Git别名。别名如下:

[alias]
public-branch = !git checkout -b $1 && git config branch.$1.autosetuprebase always && git config branch.$1.mergeoptions --ff-only && git push -u origin $1

当我单独运行别名中的每个命令时,它们都成功了。但是,运行 git公共分支功能时,我会收到以下错误输出:

Switched to a new branch 'feature'
Username for 'https://github.com': my_username
Password for 'https://username@github.com':
error: dst ref refs/heads/feature receives from more than one src.
error: failed to push some refs to 'https://github.com/username/GitTestRepo.git'

别名成功添加前两个配置属性,但在push命令上失败。我可以在配置文件中看到未成功添加跟踪信息:

[branch "feature"]
    autosetuprebase = always
    mergeoptions = --ff-only

只有当push命令是别名中列出的最后一个命令时,才会出现此错误。如果我在推送后放入 git config 命令中的任何一个,则别名会顺利运行。我猜这只是git没有正确解析别名的结果,但我看不出如何解决这个问题。您可以提供任何输入。

1 个答案:

答案 0 :(得分:0)

我更改了您的配置以使用this answerGit alias with positional parameters的别名表单,并且它运行正常:

[alias]
    public-branch = !sh -c 'git checkout -b $1 && git config branch.$1.autosetuprebase always && git config branch.$1.mergeoptions --ff-only && git push -u origin $1' -

所以基本上,把所有命令放在这个"包装器":

!sh -c '<insertCommandsHere>' -

这是结果:

$ git public-branch football
Switched to a new branch 'football'
Total 0 (delta 0), reused 0 (delta 0)
To c:/Users/Keoki/Documents/GitHub/bare
 * [new branch]      football -> football
Branch football set up to track remote branch football from origin.

并在.git/config文件中:

[branch "football"]
    autosetuprebase = always
    mergeoptions = --ff-only
    remote = origin
    merge = refs/heads/football

另见