Search code examples
gitbranchrebase

In git, how to create a branch with commits from branch A, minus commits from B, plus commits from C?


I have a local branch called local, that tracks origin.master but has a few commits that help with debugging and that are meant to never be pushed.

When I work on a feature, I start my feature branch from local. Then, when it is ready to be pushed, I want to get rid of my local commits, hence I want:
commits(feature) - commits(local) + commits(origin.master).

This looks a bit like a git rebase, but not quite.


Solution

  • That can be done like this:

    git rebase --onto origin/master local feature
    

    Which is saying: Take commits from feature that are not in local, place them on top of origin/master