【发布时间】: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 重新应用更改,然后尝试推送