简体   繁体   English

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

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

When I attempt to push my latest code to the master branch on Github using VSCode I get a pop-up error message advising the following:当我尝试使用 VSCode 将我的最新代码推送到 Github 上的 master 分支时,我收到一条弹出错误消息,建议如下:

Can't push refs to remote.无法将 refs 推送到远程。 Try running 'Pull' first to integrate your changes.首先尝试运行“Pull”以集成您的更改。

So I try a Pull, but I get a pop-up window advising me:所以我尝试了 Pull,但我收到一个弹出窗口,提示我:

There is no tracking information for that branch.该分支没有跟踪信息。

Here's the Git log for the Push:这是推送的 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.

And the Git Log for the 'Pull':以及“拉”的 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

I can see it's asking about merging - however I only have the one branch and that's the original master branch.我可以看到它在询问合并 - 但是我只有一个分支,那是原始的主分支。 There is a fair bit of code in there, but the last thing that was committed was a README.md file and I did that from GitHub itself, so I don't know if that makes a difference at all?那里有相当多的代码,但最后提交的是一个 README.md 文件,我是从 GitHub 自己做的,所以我不知道这是否有什么不同?

Your local branch is behind the remote branch you care about, so you need to pull those changes (preferably with --rebase in this case).您的本地分支位于您关心的远程分支之后,因此您需要提取这些更改(在这种情况下最好使用--rebase )。

However, git pull by default pulls from a tracked branch.但是,默认情况下git pull从被跟踪的分支中拉取。 The branch in question is not tracking anything.有问题的分支没有跟踪任何东西。

So, follow the error message's instructions and use git branch --set-upstream... , then git pull , then try git push .因此,请按照错误消息的说明使用git branch --set-upstream... ,然后是git pull ,然后尝试git push

Do below sequence执行以下顺序

  1. Git pull origin master git pull origin master
  2. resolve any merge conflicts if any解决任何合并冲突(如果有)
  3. git add . git 添加。
  4. git commit -m "....." git commit -m "....."
  5. git push

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

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