git 错误:无法将一些引用推送到远程 [英] git error: failed to push some refs to remote

查看:168
本文介绍了git 错误:无法将一些引用推送到远程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我现在不能推动,而我昨天可以做到.也许我搞砸了配置或其他什么.

事情是这样的:

当我使用 git push origin master 时

我的工作目录和远程存储库是什么样的:

解决方案

(注:从 2020 年 10 月开始,任何新存储库都使用默认分支 main 创建,而不是 master. 并且您可以将现有存储库默认分支从 master 重命名为 main.
2014 年答案的其余部分已更新为使用main")

(以下假设 github.com 本身关闭,如 eri0o评论中指出:请参见 www.githubstatus.com 以确保)>

如果 GitHub 存储库看到推送到它的新提交,而您在本地工作时,我建议您使用:

git pull --rebase推

完整的语法是:

git pull --rebase origin maingit push origin main

使用 Git 2.6+(2015 年 9 月),完成(一次)后

git config --global pull.rebase truegit config --global rebase.autoStash true

一个简单的 git pull 就足够了.
(注意:对于 Git 2.27 Q2 2020merge.autostash 也可用于您的常规拉,没有变基)

那样,您将在新更新的 origin/main(或 origin/yourBranch: git pull origin yourBranch).

第6章用rebase拉取更完整的例子Git Pocket Book.

我会推荐一个:

#先添加并提交git push -u origin main

那将在您的本地主分支与其上游分支之间建立跟踪关系.
之后,该分支的任何未来推送都可以通过一个简单的:

git push

请参阅为什么我需要明确推送新分支?".


由于 OP 已经在 origin/main 之上重置并重做其提交:

git reset --mixed origin/maingit 添加.git commit -m "这是我原计划修改的新提交";git push origin main

无需pull --rebase.

注意:git reset --mixed origin/main也可以写成git reset origin/main,因为--mixed选项是使用 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")

(The following assumes github.com itself is not down, as eri0o points out in the comments: see www.githubstatus.com to be sure)

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆