拒绝合并主分支到最新的新分支(非快速向前合并)

5
在我的代码库中,我有一个名为master的分支和一个名为new的分支。
我一直在new上工作,进行提交和推送。现在我决定从new创建并命名一个新的分支newest,于是我执行了以下操作:
git checkout -b "newest"

分支已成功创建。我添加了一个文件并开始工作。我提交了几次更改。

但是,当我尝试将这个新分支和我的更改推送到origin时,我遇到了以下错误:

C:\wamp\www\myproj>git push origin
To https://github.com/Imray/Proj.git
 ! [rejected]        master -> master (non-fast-forward)
 ! [rejected]        new -> new (non-fast-forward)
error: failed to push some refs to 'https://github.com/Imray/Proj.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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. 

所以,按照说明,我尝试了 git pull,但是出现了以下情况:

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> newest

我卡住了。

我该如何将我的新分支和更改推送到 github

2个回答

2
检查您的git config push.default。它可能设置为“matching”,因为它试图推送所有现有的分支。
这是Git 2.0+之前的默认设置
我建议将其设置为“simple”,以便仅推送当前分支。
话虽如此,要推送一个分支,您需要(第一次推送时)设置一个上游分支
对于从未推送过的分支:
git push -u origin newest

对于已经存在于上游仓库的分支:

git branch --set-upstream-to=origin/master master
git branch --set-upstream-to=origin/new new

然后执行 git checkout master;git pull 命令即可。

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接