如何在不拉动的情况下推动新分支

时间:2017-07-06 11:29:43

标签: git merge branch git-branch branching-and-merging

所以我已经开始研究新功能,我意识到在本地提交主分支会太复杂。因此,我创建了一个新的分支如下:

$ git stash branch project_0.2 stash@{0}

问题当然是当我尝试将新分支推送到服务器时,我得到:

$ git push origin master
To https://svn.tudelft.nl/git/project.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://svn.tudelft.nl/git/project.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并合并这些变化。我试过这个(在我做备份之前),然后我得到了:

$ git pull
remote: Counting objects: 1105, done.
remote: Compressing objects: 100% (304/304), done.
remote: Total 725 (delta 501), reused 552 (delta 382)
Receiving objects: 100% (725/725), 5.29 MiB | 0 bytes/s, done.
Resolving deltas: 100% (501/501), completed with 165 local objects.
From https://svn.3me.tudelft.nl/git/project
   5d6516c..fd424b5  master     -> origin/master
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> project_0.2

我不确定我应该在这做什么,所以我停了下来。此外,变化是如此之深,以至于我将永远合并。我认为可能有一种更聪明的方法将分支推送到服务器。通过这种方式,我可以从我团队的其他成员那里获得帮助来修复代码。这可能吗?

2 个答案:

答案 0 :(得分:2)

首先使用

创建新分支
git checkout -b NewBranchName

它将在您的本地计算机上创建一个新分支,现在推送这个新分支。

git push origin NewBranchName

答案 1 :(得分:1)

如果您希望将新功能与主分支中的功能隔离开来,则必须执行@UniCoder所说的操作。使用以下命令创建一个新分支:

git branch NewBranchName

使用以下命令激活它:

git checkout -b NewBranchName

进行开发,添加所需对象,提交您在此功能上完成的工作,然后创建新分支:

git push origin --set-upstream NewBranchName

对于以后的推送,您只需要输入“git push origin”