【问题标题】:Firstly I commited new repo in git with master branch and now I cant commit [duplicate]首先,我在 git 中使用 master 分支提交了新的 repo,现在我无法提交 [重复]
【发布时间】:2021-09-01 07:36:13
【问题描述】:

首先我提交了 master 分支,现在我在 main 分支中,无法更改为 master 分支。此外,如果我尝试通过主分支提交我的仓库,则会显示以下错误:-

$ git push --set-upstream https://github.com/manvith22/Evernote-clone.git main

To https://github.com/manvith22/Evernote-clone.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'https://github.com/manvith22/Evernote-clone.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
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.

abc@MA MINGW64 ~/react-redux-hooks (main)
    $ git pull <remote> master:dev
bash: remote: No such file or directory

abc@MA MINGW64 ~/react-redux-hooks (main)

    $ git pull <main> master:dev

bash: main: No such file or directory

abc@MA MINGW64 ~/react-redux-hooks (main)

    $ git pull <evernote> master:dev

There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=<remote>/<branch> main

【问题讨论】:

标签: git git-pull


【解决方案1】:

&lt;/&gt; 括号表示它是您真正指的任何分支的占位符。您无需输入括号;你只是想要

git pull https://github.com/manvith22/Evernote-clone.git main

或者很可能只是

git pull

会的。

但是,查看存储库https://github.com/manvith22/Evernote-clone 有两个分支; master main。您需要与在 repo 上工作的其他人交谈,以选择您将使用哪个分支。

【讨论】:

    【解决方案2】:

    origin 和本地提交的内容不匹配,因此第一次推送失败。

    您可以使用git pull --rebase 从远程进行更改(假设您已经在main 分支上)

    之后,您可以使用git push 命令推送更改。

    PS:&lt; 用于提供来自文件的输入,&gt; 用于将输出写入文件。通过运行git pull &lt;remote&gt; master:dev,您是说从文件remote 读取并将输出写入文件master:dev

    【讨论】:

      猜你喜欢
      • 2014-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-21
      • 2012-04-27
      • 1970-01-01
      相关资源
      最近更新 更多