1

Imagine the scenario:

You are in develop branch currently. You created new branch. Lets say A You made some commits.

But then you realized this is a hotfix and it should be based on master branch. And develop has some changes that shouldn't be in the master branch, yet. (gitflow)

So whats the easiest way to carry of all the changes to a new branch based on master?

This happened to me today. And my (stupid) solution was:

  • Delete A
  • Memorize all the changes you have made.
  • Checkout to master.
  • Create new branch. B
  • Apply your changes to this new branch.

There has to be better way! :)

love
  • 1,000
  • 2
  • 16
  • 35
Can Vural
  • 2,222
  • 1
  • 28
  • 43
  • Possible duplicate of [In git, how do I remove a commit from one branch and apply it to a different branch?](http://stackoverflow.com/questions/1773731/in-git-how-do-i-remove-a-commit-from-one-branch-and-apply-it-to-a-different-bra) – Maximilian Ast Jun 30 '16 at 11:55

1 Answers1

2

So whats the easiest way to carry of all the changes to a new branch based on master?

That's what rebase does:

git rebase --onto master development A

Now your branch is based on master.

See the docs for git-rebase, specifically the --onto section.

RemcoGerlich
  • 30,470
  • 6
  • 61
  • 79