Search code examples
gitrebasegit-pushgit-historygit-history-rewrite

How to update my feature branch after a force push on the base branch . We only use rebase, merges are forbidden


We are working with a very simple structure in git.

First we have our master branch.

Below we have develop

And finally we can have any feature branch

We only use rebase for updating the history on our branches and then f-forwarding to the above branch.

Weekly, we have our develop branch that has been updated with some features. And this branch is rebased and merged into master (from develop to master).

THE PROBLEM

When we are rebasing and merging develop to master , sometimes there are conflicts and I have to fix them by performing a master rebase into my develop branch. After fixing conflicts I perform a git push --force-with-lease to upload changes to remote.

After this procedure, the history of develop has being changed because of the force push.

The problem resides when another developer was working on a feature branch based on develop but, the one before the force push (develop before the force push).

How can we update the feature branch of this developer with the new history of develop branch. Because, when doing a git rebase develop inside our feature branch. We end up with a lot of conflicts.


Solution

  • If I understand correctly, the developper was is this situation :

    --*--x--*--m <- master
          \
           \
            *--*--f <- develop
                   \
                    a--b--c <- feature
    

    and after he fetches the update, he reaches :

    --*--x--*--m <- master
          \     \
           \     *--*--f' <- develop
            *--*--f
                   \
                    a--b--c <- feature
    

    To only replay a, b, c on top of develop, apply the command suggested by @Vitali :

    • spot commit f : the original fork point between feature and develop,
    • run : git rebase --onto develop <f> feature

    If all goes well, he will reach the following state :

    --*--x--*--m <- master
                \
                 *--*--f' <- develop
                        \
                         a'--b'--c' <- feature
    
    # only 'a--b--c' are replayed from the original 'feature' branch,
    # not '*--*--f'