【问题标题】:Trying to push to GitHub尝试推送到 GitHub
【发布时间】:2020-01-08 14:12:26
【问题描述】:

GitHub 上有一个现有的存储库。然后我在本地编写了一个项目,并尝试将push 发送到远程分支my_branch

我得到以下信息:

$ git push -u origin my_branch
To github.com:xxxx/richard-m-xxxx.git
 ! [rejected]        my_branch -> my_branch (non-fast-forward)
error: failed to push some refs to 'git@github.com:xxxx/richard-m-xxxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

它说我的本地分支 (my_branch) 在远程分支后面。我试过git pull,但它看起来是最新的。

$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> my_branch

请有人告诉我push我的项目到远程分支my_branch的步骤吗?

谢谢。

更新

我也尝试了以下失败:

$ git pull origin my_branch
From github.com:xxxx/richard-m-xxxx
 * branch            my_branch  -> FETCH_HEAD
fatal: refusing to merge unrelated histories

再说一遍:

$ git push origin my_branch
To github.com:xxxx/richard-m-xxxx.git
 ! [rejected]        my_branch -> my_branch (non-fast-forward)
error: failed to push some refs to 'git@github.com:xxxx/richard-m-xxxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

【问题讨论】:

  • 我会仔细检查您是否从正确的目录推送。尝试 cd 到另一个目录,然后返回。如果这不起作用 git stash 你的更改,与远程同步,使用 git stash pop 重新应用更改,然后尝试推送

标签: git github


【解决方案1】:

我在这里找到了解决方案:https://github.community/t5/How-to-use-Git-and-GitHub/How-to-deal-with-quot-refusing-to-merge-unrelated-histories-quot/td-p/12619

git pull --allow-unrelated-histories origin my_branch

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-18
    • 2012-11-06
    • 2020-08-09
    • 2020-02-06
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多