【问题标题】:How can I push the changes as the master branch (default)? [duplicate]如何将更改作为主分支推送(默认)? [复制]
【发布时间】:2022-01-25 20:00:45
【问题描述】:

我在 4 个月前将我的项目与 Github 相关联,今天我无意中删除了我的项目,因此我从 Github 重新安装了最后一次提交并在 Android Studio 中打开它,但是当我进行任何更改时,我无法将它作为主分支推送到 Github,但是如果我将它作为不同的分支推送它可以工作,我如何将更改作为主分支推送(默认)?

在控制台中显示详细信息

12:48:16.974: [Project] git -c credential.helper= -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/master:master --set-upstream
error: failed to push some refs to 'https://github.com/.../...'
hint: Updates were rejected because the remote contains work that you do
To https://github.com/.../...
!   refs/heads/master:refs/heads/master [rejected] (fetch first)
hint: not have locally. This is usually caused by another repository pushing
Done
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

【问题讨论】:

  • 找出为什么推送被拒绝(查看图片中的“在控制台中显示详细信息”标签)。
  • @DrHowdyDoo 我知道问题出在哪里,但我不知道如何解决,问题是 Github 认为我不是项目的所有者,所以它允许我创建我的仅分支,但我如何告诉 Github 我是项目所有者,即使我可以更新主分支?我以前看过这个链接,但对我不起作用。
  • @SwissCodeMen 我以前看到过这个链接,但对我不起作用。
  • @torek 检查更新

标签: android git android-studio github intellij-idea


【解决方案1】:

您可以从控制台尝试 git push,它既可以正常工作,也可以告诉您确切的问题是什么,并使用备用命令(例如git push --set-upstream)来修复它。

PS 尝试从任何地方(youtube/pluralsight)等学习 git 基础知识,并尽可能多地使用命令行我已经切换到命令行 2 年了,我对 git 的理解有了很大的提高,而且它有助于避免工作室有任何令人讨厌的问题。

编辑 - 正如相关更新所指出的,您需要在推送之前通过git pull 提取最新更改。

【讨论】:

    【解决方案2】:

    在 Android Studio>Git>Branches>Remote Branches 中选择 master 作为远程分支

    【讨论】:

    • 我已经选择了master分支,查看上图
    • 可能有两个原因: 1. 您设置了错误的远程 URL。 2.你电脑的ssh key过期或者没有添加到你的git设置ssh列表中。
    • 我知道问题出在哪里,但我不知道如何解决,问题是 Github 认为我不是项目的所有者,所以它只允许我创建我的分支但是我怎么能告诉 Github 我是项目所有者,即使我可以更新 master 分支?
    猜你喜欢
    • 2022-12-04
    • 1970-01-01
    • 2020-07-13
    • 2021-11-21
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多