git 无法推送到 master 分支

Sus*_*ha7 1 git bash github

  1. github 中的 git 存储库包含以下分支 (master,'abc' )
  2. 将 git repo abc 分支克隆到本地计算机
  3. 使用 git bash 进入 repo 文件夹
  4. 创建名为的 git 分支bbb
  5. 到分行结账bbb
  6. 将文件添加到 repo 文件夹
  7. 提交更改
  8. 使用以下命令将更改推送到远程存储abc库分支:

    git push origin bbb:abc
    
    Run Code Online (Sandbox Code Playgroud)

    效果很好。

  9. 然后使用以下命令将更改推送到远程存储库主分支:

    git push origin bbb:master
    
    Run Code Online (Sandbox Code Playgroud)

然后出现以下错误消息:

 ! [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.
Run Code Online (Sandbox Code Playgroud)

有人能解释为什么会发生这种情况吗?

Ali*_*ani 5

正如 git 本身所说:

hint: (e.g. 'git pull ...') before pushing again.
Run Code Online (Sandbox Code Playgroud)

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

出现此错误的原因是您的本地版本与 github 存储库中的版本不同,您应该以某种方式协调这两个版本以便能够使用push您的代码。