git push 'pushing'不是新分支

标签 git git-push git-remote

我从我们的仓库中 checkout 了一个新分支。我们的开发分支一切正常。但是在新分支上,“推送”没有做任何事情。

一切看起来都很正常 - 有 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 会像您描述的那样工作,因为您遇到以下情况:

  • 您有一个本地分支 (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 分支。第二个适用于该存储库中的所有跟踪分支(如果使用了全局选项,则全局适用)。

关于git push 'pushing'不是新分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18214981/

相关文章:

git - 如果我重置它,为什么我在 git diff 中看不到文件?

bitbucket - 从 SourceTree 推送到 BitBucket

Git:用 'post-receive'命令发送参数到 'git push' hook

git - git 在推送非快进提交时如何丢失历史记录?

git - git push origin 和 git push origin master 有什么区别

git - git pull命令输出消息含义到哪个分支

git - 如何使 'git push' 像 'git push origin branch' 一样工作?

git - 如何列出未推送的 Git 标签

windows - Git - 推送新的提交并忽略未提交的更改

git - 如何在 TFS 2012 Update 2(自托管)中启用 GIT 支持