Search code examples
gitrebase

How to rebase feature branch on dev branch and then update dev


I have this

a -- b -- c -- f                   <-- dev
       \
        d -- e -- g              <-- feature

I want this

a -- b -- c -- f -- d -- e -- g  <-- dev

I know this is related to the rebase command. However, when I type git rebase dev feature, commits go to feature branch and dev is not updated. If I use git rebase feature dev then last commits are those from master and I have duplicates commits. How can I achieve this ?


Solution

  • Assuming I want feature to remain where it is without moving it (as showing in the final chart), I would do it like this:

    git checkout dev
    git cherry-pick dev..feature
    

    That's it

    If you want to delete feature branch after that:

    git branch -D feature
    

    In general, a cleaner approach (but with more steps) is:

    git checkout feature
    git rebase dev
    git checkout dev
    git merge feature # (this fill fast-forward to the tip of feature)
    git branch -d feature # no need to use -D this time