0

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.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193

1 Answers1

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

Ralf Wagner
  • 1,467
  • 11
  • 19