2017-07-17 74 views
2

我已经设置了我目前的分支dev推到refs/remotes/test与以下git push --set-upstream origin dev:test如何设置当前分支(dev)推到ref /远程/测试与git推只?

.git/config样子:

[remote "origin"] 
    url = https://[email protected]/appulocal/test_st.git 
    fetch = +refs/heads/*:refs/remotes/origin/* 
[branch "dev"] 
    remote = origin 
    merge = refs/heads/test 

但是当我做git push它不会从本地devtest远程。 的Git的bash显示消息:

fatal: The upstream branch of your current branch does not match 
the name of your current branch. To push to the upstream branch 
on the remote, use 

    git push origin HEAD:test 

To push to the branch of the same name on the remote, use 

    git push origin dev 

To choose either option permanently, see push.default in 'git help config'. 

,这样如何解决这个只上远程执行git push我当前分支dev推向test

+0

'要永久选择任一选项,请参阅'git help config'中的push.default。 – smarber

回答

0

其实你已经设置了dev拉到refs/remotes/test。这就是该分支的merge选项管辖的内容。这有点令人困惑,因为这是使用push命令设置的;但是一组不同的配置选项决定了推送行为的方式。

事情是,git检查一些事情来决定如何处理推送,而我们大多数人习惯的行为是默认设置,当它们都没有设置时... 但是 git isn如果分支名称不匹配,则不愿意依赖该默认值,因为它认为这可能是您尝试使用的两种不同配置之间的不明确。

对于您的情况,您希望为您的dev分支指定推送目标test。有几种方法可以解决这个问题,但我想不出任何没有副作用,当你在不同的分支并且说git push

假设你只推到一个远程 - 和它的你拉同一个 - 你可以设置push.default配置值

git config push.default upstream 

这消除了“同名”的检查。 (请注意,它将取消所有分支机构的检查;但只要您打算总是推送到您在pull期间合并的任何分支即可)。官方文档认为这仅适用于单一远程工作流程。

如果您想要更精确地指定什么会推到哪里,您可能只需在push命令行中指定refspecs。