Built a project on the company's git server, then create a branch b1
Then add a github master
git remote add r1 https://github.com/xx/xx
How to merge the local branch b1 and the remote r1 branch?
Additional edit, the original requirement is to do secondary development on an active project on github, and also put the code on the company git. Do you have any good suggestions? Thank you
If you want to merge two branches, you must at least ensure that they have the same ancestor. According to the original poster, they do have the same ancestor, so they can be merged.
In this case, my plan is to first use the
git clone
命令克隆的本地,然后使用git remote add ...
命令添加公司git服务器上的仓库为远程仓库;接着在本地使用git pull
命令进行拉取与合并,当然git pull
command for the project in the github warehouse and then add the url alias and branch name of the remote branch; finally, if the conflict is resolved and the merge is completed, it can be pushed to the company's remote warehouse.I think it might be safer to merge in another local warehouse like this. Of course, because I have never actually dealt with such a problem, if my solution does not succeed, I hope the poster can give me feedback on what the problem is.
git push
You can choose which remote server to use, so first pull the branch from github, resolve the conflict, and then push it to the master of the company branch, and wait for people from the company to check the merge. There should be no problemAccording to the questioner,
r1
is actually not a branch, but a remote. Let's first assume that you want to merge the local b1 branch and the master branch of r1.Now that you have added r1, all you need to do is:
First switch to b1. The command is
git checkout b1
Get the HEAD pointer of r1 master branch. The command is
git fetch r1
Apply the content on r1 master branch to local. Available
git merge r1/master
,也可以git rebase r1/master
. The former generates non-linear history records, and the latter generates linear ones.Then you push it to the company’s library and you’re done
By the way:
git pull
=git fetch
+git merge
git pull
=git fetch
+git merge
git pull --rebase
=git fetch
+git rebase
git pull --rebase
=git fetch
+git rebase