Home  >  Q&A  >  body text

怎么合并github master 和 自己从公司git上checkout的分支?

在公司git服务器上建了一个项目,然后建立一个分支 b1
然后添加了一个github的master
git remote add r1 https://github.com/xx/xx

怎么合并本地分支b1和远程r1分支呢?

补充编辑,原始需求是在一个github活跃的项目上面做二次开发,又要将代码放到公司git上,或者大家有什么好的建议? 谢谢

漂亮男人漂亮男人2727 days ago675

reply all(3)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-02 09:46:44

    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 pullcommand 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.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-02 09:46:44

    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 problem

    reply
    0
  • 为情所困

    为情所困2017-05-02 09:46:44

    According 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:

    1. First switch to b1. The command is git checkout b1

    2. Get the HEAD pointer of r1 master branch. The command is git fetch r1

    3. 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 mergegit pull = git fetch + git merge
    git pull --rebase = git fetch + git rebasegit pull --rebase = git fetch + git rebase

    reply
    0
  • Cancelreply