繁体   English   中英

从 VSCode 推送到 GitHub 上的远程主分支时出错

[英]Error when pushing to remote master branch on GitHub from VSCode

当我尝试使用 VSCode 将我的最新代码推送到 Github 上的 master 分支时,我收到一条弹出错误消息,建议如下:

无法将 refs 推送到远程。 首先尝试运行“Pull”以集成您的更改。

所以我尝试了 Pull,但我收到一个弹出窗口,提示我:

该分支没有跟踪信息。

这是推送的 Git 日志:

> git push origin master
To https://github.com/WebDevelopWolf/Date-A-Dog.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/WebDevelopWolf/Date-A-Dog.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

以及“拉”的 Git 日志:

> git pull --tags
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=origin/<branch> master

我可以看到它在询问合并 - 但是我只有一个分支,那是原始的主分支。 那里有相当多的代码,但最后提交的是一个 README.md 文件,我是从 GitHub 自己做的,所以我不知道这是否有什么不同?

您的本地分支位于您关心的远程分支之后,因此您需要提取这些更改(在这种情况下最好使用--rebase )。

但是,默认情况下git pull从被跟踪的分支中拉取。 有问题的分支没有跟踪任何东西。

因此,请按照错误消息的说明使用git branch --set-upstream... ,然后是git pull ,然后尝试git push

执行以下顺序

  1. git pull origin master
  2. 解决任何合并冲突(如果有)
  3. git 添加。
  4. git commit -m "....."

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM