[英]how to git push to a local branch?
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 masterto push to the remote repository, but I want to push to a local branch.
Thanks谢谢
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
如果您真的想将本地分支推送到另一个本地分支,请使用
git push . B:master
git push . B:master
, though this is quite rare. git push . B:master
,虽然这种情况很少见。
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 也可以这样做
https://git-scm.com/docs/git-merge https://git-scm.com/docs/git-merge
As others said, normally you want to switch to A and then merge from B instead.正如其他人所说,通常你想切换到A然后从B合并。
However, if you do it regularly, in some edge cases it makes sense to set A as upstream branch for B但是,如果您经常这样做,在某些边缘情况下,将A设置为B 的上游分支是有意义的
git checkout B
git branch --set-upstream-to A
# shorthand: git branch -u A
and then use git push from branch B like you asked.然后按照您的要求使用分支B 的git push 。
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"
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 分支)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.