Home > Mobile >  Created branch from development, worked on it, now I want to merge this to master without merging de
Created branch from development, worked on it, now I want to merge this to master without merging de

Time:08-17

It took me a while to create a proper and simple title for this question.

I was working on the development branch code and then I realized that the task I have completed will be pushed to master. The problem now is my branch contains development work as well, because I have created the branch from development.

I tried to search this on the internet but maybe I could not find the proper search terms.

Please can anyone help me with merging my work to master directly without merging the development code, Thanks.

CodePudding user response:

Just switch to your master branch and cherry-pick your commits that you want to be in master. Don't forget to update your master branch by pulling before cherry-picking.

git commit // commit your work on the development branch
git log HEAD~n // to learn the commit id's.
                // Replace n with number of commits you want to see
git checkout master
git pull
// cherry-pick in the order from earliest to the latest
git cherry-pick <commit-id-1>
....
git cherry-pick <commit-id-n>

CodePudding user response:

Suppose your branch is called my-branch. You can use this one-liner to rewrite your branch as if you originally branched off of master instead of development:

git rebase development my-branch --onto master

In words, the above command says:

Take all of the commits on my-branch that are not reachable by development, and replay them one by one, in order, onto master.

  • Related