当我试图将我的代码推送到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存储库中解决了这个问题。在这种情况下,不需要重新设置或强制提交。使用以下步骤解决此问题-

local_barnch> git branch --set-upstream to=origin/<local_branch_name> 

local_barnch>git pull origin <local_branch_name>

local_barnch> git branch --set-upstream to=origin/master

local_barnch>git push origin <local_branch_name>

希望能有所帮助。

其他回答

只是有同样的问题,但在我的情况下,我在遥控器上输入了错误的分支。所以,这似乎是这个问题的另一个来源……仔细检查你是否推到了正确的分支。

git pull origin branch_name --rebase

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

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

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

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

Git push -f origin branchname

只有当您确定不需要远程分支代码时,才使用上述命令,否则请先合并,然后再推送代码