如何 git push 到本地分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38868224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to git push to a local branch?
提问by chipbk10
I git clone a project on my computer and have a local master branch, let say A. Here, I create some local branches (let say B and C).
我在我的计算机上 git clone 一个项目并有一个本地 master 分支,比如说 A。在这里,我创建了一些本地分支(比如说 B 和 C)。
I made some changes in B and C. So, how do I can git push to merge the changes in B and C to A?
我在 B 和 C 中做了一些更改。那么,我如何 git push 将 B 和 C 中的更改合并到 A?
Normally, I see that
通常,我看到
git push origin master推送到远程存储库,但我想推送到本地分支。
Thanks
谢谢
回答by ElpieKay
Use git merge
instead to manipulate local branches.
使用git merge
代替来操作本地分支。
git checkout master
git merge B
git merge C
If you really want to push a local branch to another local branch, git push . B:master
, though this is quite rare.
如果你真的想把一个本地分支推送到另一个本地分支git push . B:master
,虽然这种情况很少见。
回答by Dennis Kotsch
While on the master branch, have you tried
在 master 分支上,您是否尝试过
git merge B
This should merge your local branch B back into master, same can be done for branch C
这应该将您的本地分支 B 合并回主分支,分支 C 也可以这样做
回答by user185953
As others said, normally you want to switch to Aand then merge from Binstead.
正如其他人所说,通常你想切换到A然后从B合并。
However, if you do it regularly, in some edge cases it makes sense to set Aas upstream branch for B
但是,如果你经常这样做,在某些边缘情况下,将A设置为B 的上游分支是有意义的
git checkout B
git branch --set-upstream-to A
# shorthand: git branch -u A
and then use git pushfrom branch Blike you asked.
然后按照您的要求使用分支B 的git push。
回答by Veer
If You want to merge branch A to B
如果要将分支 A 合并到 B
First commit your changes, if you have done any changes and want that changes to be merged to B branch
首先提交您的更改,如果您进行了任何更改并希望将这些更改合并到 B 分支
git add --file path--
: adds files to stage and then
git add --file path--
: 将文件添加到舞台,然后
git commit -m "add commit msg"
git commit -m "add commit msg"
and then git checkout B
, you will be now in B branch.
然后git checkout B
,您现在将在 B 分支。
git merge --no-ff A
(we are doing non fast forward merge, merging branch A into B branch)
git merge --no-ff A
(我们在做非快进合并,将分支 A 合并到 B 分支)