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

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


当前回答

当我试图推我当前的分支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提交并尝试在git拉到其他人已经做了更改的分支x之前进行git推送更改时。

正常的流程如下:

步骤1:git将本地未提交的更改保存在该分支上。

步骤2:git拉origin branch_name -v来拉并合并到本地提交的分支上的更改(给这个合并一些消息,如果有的话修复冲突)。

步骤3:git隐藏弹出隐藏的更改(然后你可以在弹出的文件上提交,如果你想要,或者先推送已经提交的更改(STEP4),然后再将新的提交到文件中。)

步骤4:git推送origin branch_name -v合并后的更改。

将branch_name替换为master(用于主分支)。

Git push -f origin branchname

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

有时我们忘记了牵引,在当地环境中做了很多工作。

如果有人想只推不拉,

git push --force

是有效的。当你和其他人一起工作时,不建议这样做,但当你的工作是一件简单的事情或一个私人玩具项目时,这将是一个快速的解决方案。

我已经在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>

希望能有所帮助。