git错误:无法将一些引用推送到远程 [英] git error: failed to push some refs to remote
问题描述
由于某种原因,我现在不能推动,而昨天却可以. 也许我搞砸了配置或其他东西.
会发生这种情况:
当我使用git push origin master时
我的工作目录和远程存储库是什么样的:
的屏幕截图.
(注意:将现有存储库默认分支从master
重命名为main
.
该2014年答案的其余部分已更新为使用"main
")
如果在本地工作时GitHub存储库中看到有新的提交提交,我建议使用:
git pull --rebase
git push
完整语法为:
git pull --rebase origin main
git push origin main
(一次)完成后,使用Git 2.6+ (2015年9月)
git config --global pull.rebase true
git config --global rebase.autoStash true
一个简单的git pull
就足够了.
(注意:对于 Git 2.27 Q2 2020 ,merge.autostash
也可用于常规拉动,而无需重新设置基准)>
这样,您将在新更新的origin/main
(或origin/yourBranch
:git pull origin yourBranch
)之上重播(--rebase
部分)本地提交.
请参见第6章中的更完整示例 .
我建议:
# add and commit first
git push -u origin main
这将在您的本地主分支与其上游分支之间建立跟踪关系.
之后,将来可以使用以下简单的方法对该分支进行任何推送:
git push
请参见"为什么需要显式推送新分支?".
由于OP已经在origin/main
顶部重置并重做其提交:
git reset --mixed origin/main
git add .
git commit -m "This is a new commit for what I originally planned to be amended"
git push origin main
不需要pull --rebase
.
注意:git reset --mixed origin/main
也可以写为git reset origin/main
,因为在使用--mixed选项是默认选项. ="noreferrer"> git reset
.
For some reason, I can't push now, whereas I could do it yesterday. Maybe I messed up with configs or something.
This is what happens:
When I use the git push origin master
What my working directory and remote repository looks like:
(Note: starting Oct. 2020, any new repository is created with the default branch main
, not master
. And you can rename existing repository default branch from master
to main
.
The rest of this 2014 answer has been updated to use "main
")
If the GitHub repo has seen new commits pushed to it, while you were working locally, I would advise using:
git pull --rebase
git push
The full syntax is:
git pull --rebase origin main
git push origin main
With Git 2.6+ (Sept. 2015), after having done (once)
git config --global pull.rebase true
git config --global rebase.autoStash true
A simple git pull
would be enough.
(Note: with Git 2.27 Q2 2020, a merge.autostash
is also available for your regular pull, without rebase)
That way, you would replay (the --rebase
part) your local commits on top of the newly updated origin/main
(or origin/yourBranch
: git pull origin yourBranch
).
See a more complete example in the chapter 6 Pull with rebase of the Git Pocket Book.
I would recommend a:
# add and commit first
git push -u origin main
That would establish a tracking relationship between your local main branch and its upstream branch.
After that, any future push for that branch can be done with a simple:
git push
See "Why do I need to explicitly push a new branch?".
Since the OP already reset and redone its commit on top of origin/main
:
git reset --mixed origin/main
git add .
git commit -m "This is a new commit for what I originally planned to be amended"
git push origin main
There is no need to pull --rebase
.
Note: git reset --mixed origin/main
can also be written git reset origin/main
, since the --mixed
option is the default one when using git reset
.
这篇关于git错误:无法将一些引用推送到远程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!