当我试图将我的代码推送到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.

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


当前回答

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

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

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

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

git checkout test

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

git checkout -b testing

现在,是时候推它了:

git push [remote repo] testing

其他回答

如果git pull print Already - up- up,那么你可能想检查全局git push.default参数(In ~/.gitconfig)。如果匹配,则将其设置为simple。下面的答案解释了原因:

Git: push.default "matching"和"simple"有什么区别?

此外,使用git remote show origin检查您的本地分支是否过期,并在需要时进行拉取也是值得的

当我将最新的更改推到我用于gitweb的裸Git存储库时,我得到了类似的错误。在我的例子中,我没有在裸库中做任何更改,所以我只是删除了我的裸库并再次克隆:

git clone --bare <source repo path> <target bare repo path>

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

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

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

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

在我的情况下,我检查了“mybranch”,并做了git pull,所以我不知道为什么推不起作用。最后,我意识到我推错了树枝。我输入的是git push origin master而不是git push origin mybranch。

如果你已经做了git pull,仍然收到这个消息,确保你推的是正确的分支。

使用push命令的问题是本地和远程存储库不匹配。如果你在从git hub创建新的存储库时默认初始化了自述库,那么主分支会自动创建。然而,当你试图推动,没有任何分支。你不能推…因此,最好的做法是创建没有默认自述me初始化的repo。