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

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


当前回答

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

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

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

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

其他回答

当我试图推我当前的分支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进行清理

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

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

我已经在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 pull origin branch_name --rebase

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