turning a fork to a new branch of an existing branch

扶醉桌前 提交于 2021-01-29 11:47:21

问题


Consider that you have a repository https://gitlab.com/my_repo with at least two branches Master and Develop. You have forked the repo into a private one https://gitlab.com/my_repo_fork. You have applied some edits to the Master branch. Now you want to turn the local Master into a new branch of the original repo, branched from the Develop branch. So What I have

  • https://gitlab.com/my_repo

    • Master
    • Develop
  • https://gitlab.com/my_repo_fork

    • Master* (edited)
    • Develop

and what I want to have:

  • https://gitlab.com/my_repo
    • Master
    • Develop
    •      |-> Improvment/number (from the edited Master*)

I would appreciate it if you could help me know what is the safest way to do this. Thanks for your support in advance.


回答1:


I would create a branch from master, commit the changes and rebase the branch onto the develop branch and then solve merge conflicts:

On master

git checkout -b Improvement/number // create the new branch and add changes
git add .
git commit -m "<message>
git rebase Develop                 // rebase the new branch onto Develop

Initially, the new branch contains the changes from master:

https://gitlab.com/my_repo_fork

Master (now clean)
|-> Improvment/number
Develop

The rebase removes ("cuts") the branch from master and applies the changes to Develop:

Master (now clean)
Develop
|-> Improvment/number

For a description with better graphics see https://git-scm.com/book/en/v2/Git-Branching-Rebasing



来源:https://stackoverflow.com/questions/60771382/turning-a-fork-to-a-new-branch-of-an-existing-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!