【问题标题】:Git push is not 'pushing' a new branchGit push 不是“推送”一个新分支
【发布时间】:2013-08-15 10:00:11
【问题描述】:

我从我们的 repo 中签出了一个新分支。我们的开发分支一切正常。但是在新分支上,“push”什么也没做。

一切看起来都很正常 - 有 2 个提交要推送。

-> git branch -vv
  develop   8ab7ef1 [origin/develop] Merge branch 'develop' of git.example.com:core-platform into develop
* hotfix112 8521cef [origin/hotfix/1.1.2: ahead 2] CORE-1263 - Completed merging from dev into hot fix.

但是 Push 什么也没做:

-> git push
Everything up-to-date

-> git status
# On branch hotfix112
# Your branch is ahead of 'origin/hotfix/1.1.2' by 2 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean

我发现 'git pull' 使用远程,但 'git push' 没有:

-> git remote show origin
* remote origin
  Fetch URL: git@git.example.com:core-platform.git
  Push  URL: git@git.example.com:core-platform.git
  HEAD branch: develop
  Remote branches:
    core-platform-1.0.0 tracked
    develop             tracked
    hotfix/1.1.2        tracked
    master              tracked
    release/1.0.0       tracked
    release/1.1.1       tracked
  Local branches configured for 'git pull':
    develop   merges with remote develop
    hotfix112 merges with remote hotfix/1.1.2
  Local ref configured for 'git push':
    develop pushes to develop (up to date)
->

我不明白为什么 hotfix112 没有链接到遥控器,但 pull 是。

如何修复此配置?

【问题讨论】:

标签: git git-push git-remote


【解决方案1】:

Git 的行为正如您所描述的,因为您有以下情况:

  • 您有一个本地分支 (hotfix112),它正在跟踪一个不同名称的远程分支
  • 您将 push.default 选项设置为匹配(默认)或简单

与通常使用 git 的情况一样,您有几种选择来设置 git 以按需要运行:

1.) 最简单的方法是更改​​本地分支的名称以匹配远程分支的名称。之后,推送开始自动工作。所以只需将分支 'hotfix112' 重命名为 'hotfix/1.1.2':

git branch -m hotfix112 hotfix/1.1.2

2.) 您可以通过将选项 push.default 设置为“跟踪”来更改推送行为。因为您已经将分支 'hotfix112' 设置为跟踪 origin/hotfix/1.1.2,所以 git push 将按需要工作。设置本地 git 选项运行:

git config --local push.default tracking

3.) 您可以手动编辑 .git/config 文件并将推送设置为将本地 refspec 'hotfix112' 与远程 'hotfix/1.1.2' 匹配。您应该在 [remote "origin"] 部分下方添加推送行:

[remote "origin"]                                                               
  url = ...
  fetch = ...
  push = hotfix112:hotfix/1.1.2

第一种和第三种方法仅适用于 hotfix112 分支。第二个适用于该存储库中的所有跟踪分支(如果使用全局选项,则全局使用)。

【讨论】:

  • simple 将是 2.0 中 push.default 的值,但匹配目前是默认值 (git-scm.com/docs/git-config)。
  • 你说得对,Eric,我忘了我刚才在我的全局配置中设置了它......已经相应更新......干杯!
  • 谢谢,我选择了#1。较短的分支名称似乎是个好主意,但会导致下游混淆。
  • 但为什么 Git 会说 Everything up-to-date 而不是“本地分支名称与远程分支名称不匹配并且 push.default 设置为 X”之类的东西?
【解决方案2】:

git push(不带任何附加参数)的当前行为是将所有具有相同名称的分支推送到本地和远程存储库中。由于您的本地分支名称与远程分支名称不同,如果您将它们更改为匹配,git push 应该推送您的更改。请注意,这种行为将在 git 的未来版本(可能是 2.0)中发生变化。请参阅:http://article.gmane.org/gmane.comp.version-control.git/193308。如果您想立即更改 git push 的行为,请输入 git help config 并搜索“push.default”。

【讨论】:

    【解决方案3】:

    尝试 git push origin/hotfix/1.1.2 (远程分支) hotfix112 (本地分支),可能在推送到远程之后它会创建一个链接。奇怪的是,当你分支时并没有这样做。

    【讨论】:

    • 感谢您的提示。这很好用:git push origin hotfix112:hotfix/1.1.2。但可惜配置没有改变。
    • 宾果游戏:git push -u origin hotfix112:hotfix/1.1.2Branch hotfix112 set up to track remote branch hotfix/1.1.2 from origin.
    猜你喜欢
    • 2021-06-28
    • 2016-07-13
    • 2016-04-25
    • 1970-01-01
    • 2010-10-24
    • 2016-12-24
    • 2014-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多