【问题标题】:How to setup current branch (dev) to push to refs/remotes/test with git push only?如何设置当前分支(dev)以仅使用 git push 推送到 refs/remotes/test?
【发布时间】:2017-12-22 00:40:55
【问题描述】:

我已将当前分支 dev 设置为使用以下 git push --set-upstream origin dev:test 推送到 refs/remotes/test

.git/config 看起来像:

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

但是当我执行git push 时,它不会从本地dev 推送到远程test。 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

【问题讨论】:

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

标签: git git-remote


【解决方案1】:

实际上你已经将dev 设置为refs/remotes/test 拉取。这就是分支的merge 选项所管理的内容。这有点令人困惑,因为这是使用push 命令设置的;但是一组不同的配置选项控制着推送的行为。

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

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

假设您只推送到一个遥控器 - 并且它与您拉出的遥控器相同 - 您可以设置 push.default 配置值

git config push.default upstream

这将删除“同名”检查。 (请注意,它会删除对所有分支的检查;但只要您打算始终推送到您在pull 期间合并的任何分支,就可以。)官方文档认为这仅适用于单远程工作流。

如果您想更精确地指定推送到何处的方式,您可能只需要在推送命令行上指定 refspecs。

【讨论】:

    猜你喜欢
    • 2016-12-24
    • 2013-12-01
    • 1970-01-01
    • 2016-07-13
    • 2013-03-19
    • 2017-12-07
    • 2012-08-26
    • 1970-01-01
    • 2019-02-18
    相关资源
    最近更新 更多