当我试图将我的代码推送到GitHub时,我遇到了一些问题。

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

我还没有在存储库中推入任何东西,那么为什么我需要拉出一些东西呢?


当前回答

我遇到了同样的问题,我所做的是我首先用这个力推它

git push --force

我这样做后,我提交了文件,并得到了一个错误。它确实提交了所有文件并推送了它们。 然后当我第二次推送到github时,我按照它的要求做了,然后就没问题了。希望这对你也有用:)

其他回答

您的分支名称是否与远程分支名称相同?

如果没有,您应该签出一个与远程分支同名的新分支,并尝试再次推送它。

假设要推送的远程分支是[testing],本地分支名为[test]。

如果你不在测试分支,首先切换到它。

git checkout test

然后打开一个新的分支并命名为testing。

git checkout -b testing

现在,是时候推它了:

git push [remote repo] testing

当我试图推我当前的分支foobar时,我得到了上面提到的错误消息:

git checkout foobar
git push origin foo

结果是我有两个本地分支跟踪同一个远程分支:

foo -> origin/foo (some old branch)
foobar -> origin/foo (my current working branch)

它为我工作,通过使用我的当前分支:

git push origin foobar:foo

... 并使用git分支-d进行清理

您将无法将更改推送到远程分支,除非您取消阶段性文件,然后保存本地更改,并应用来自远程的pull,然后您可以将更改推送到远程。

步骤如下—> .单击“确定”

git重置-soft HEAD~1(获取阶段性文件)

Git状态(检查暂存的文件)

Git恢复—分段<文件..>(恢复分级)

Git存储(保存当前更改)

Git pull(从远程获取更改)

Git stash apply(应用本地更改,以便添加和提交)

Git add <files…>(添加本地文件提交)

Git commit -m commit msg

git push

git pull origin branch_name --rebase

这对我来说是可行的——命令git pull origin branch_name——rebase将首先从远程branch_name中提取更改,然后在其顶部重新设置当前分支。

我在我的教程《如何使用GitHub:初学者教程》中提到了这一点。

当你在GitHub上创建一个新的存储库时,GitHub可能会要求你创建一个自述文件。如果你直接在GitHub上创建自述文件,那么你需要首先在“推送”请求成功之前发出“拉”请求。 这些命令将“拉”远程存储库,将其与当前文件合并,然后将所有文件“推”回GitHub:

git pull https://github.com/thomas07vt/MyFirstRepo.git master

git push https://github.com/thomas07vt/MyFirstRepo.git master