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

希望能有所帮助。

其他回答

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

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

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

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

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

Git存储(保存当前更改)

Git pull(从远程获取更改)

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

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

Git commit -m commit msg

git push

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

这可能导致远程存储库丢失提交;小心使用。

如果你不希望将远程分支合并到本地分支(参见git diff的区别),并且想要强制推送,请使用push命令和-f

git push -f origin <branch>

原点是远程回购的名称。

通常,该命令拒绝更新不是用于覆盖它的本地引用的祖先的远程引用。这个标志禁用检查。这可能导致远程存储库丢失提交;小心使用。

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

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

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

使用git拉https://github.com/username/repository 这是因为Github和远程存储库不同步。如果你拉了repo,然后Push,一切都会同步,错误就会消失。

`