【问题标题】:git cannot push to master branchgit 无法推送到 master 分支
【发布时间】:2015-12-26 13:03:41
【问题描述】:
  1. github 中的 git 存储库包含以下分支 (master,'abc')
  2. 克隆 git repo abc 分支到本地机器
  3. 使用 git bash 进入 repo 文件夹
  4. 创建名为bbb的git分支
  5. 结账到分行bbb
  6. 将文件添加到 repo 文件夹
  7. 提交更改
  8. 将更改推送到远程仓库abc 分支 使用了这个命令:

    git push origin bbb:abc
    

    效果很好。

  9. 然后将更改推送到远程 repo master 分支 使用了这个命令:

    git push origin bbb:master
    

然后出现以下错误信息:

 ! [rejected]        bbb -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/sw7x/testing4.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

谁能解释为什么会这样?

【问题讨论】:

  • 在您的克隆和推送期间是否有人推送了更改?
  • 如果你想强推,试试push -f

标签: git bash github


【解决方案1】:

正如 git 自己所说:

hint: (e.g. 'git pull ...') before pushing again.

首先来自 master 的 pull(甚至是 fetch),进行所需的更改,最后是 push。如果你是一个刻薄的人并且关心别人的变化,你可以使用push -f强制推送。

您收到此错误的原因是您的本地版本与驻留在 github 存储库中的版本不同,您应该以某种方式协调这两者以便能够push 您的代码。

【讨论】:

  • 那么为什么这样做可以将更改从本地 bbb 分支推送到远程 repo abc 分支使用此命令 git push origin bbb:abc 它工作正常
  • 也许是因为你是唯一一个在分支 abc 上工作的人
  • 根据您的描述,ABC 分支在您的本地存储库和 github 中都位于 master 后面。
  • ABC分支在master分支后面是什么意思?
猜你喜欢
  • 2016-11-13
  • 2012-07-25
  • 2011-11-24
  • 2015-08-14
  • 2020-09-16
  • 2014-04-01
  • 2021-10-02
  • 1970-01-01
  • 2015-11-29
相关资源
最近更新 更多