leezer3 leezer3 - 5 months ago 38
Git Question

GIT: Updating a feature branch with changes in master without merge

I'm working on a relatively large GIT repository, which I think follows a reasonably standard setup as follows: Features are developed in new branches, and then get merged back into master.

~6 months ago, a feature was partially implemented on a new branch. It turned out that this feature depended on a bunch of other stuff, and so it was put on the back burner until the other stuff was completed.
This leaves the branch in question 18 commits ahead of master, and 93 commits behind, and has a mix of contributors, so we don't want to squash it or loose the history.

How do I get the current changes from master onto the feature branch please?

Only thing I can think of at the moment is merging into master and then immediately re-branching, but there must be a better method of doing this, as the feature is incomplete....


You have two options:

  1. Merge master into feature:

    $ git checkout feature
    $ git merge master

    This has the disadvantage that you have to resolve all conflicts at one time.

  2. Rebase feature onto master:

    $ git checkout feature
    $ git rebase master

    If there are any conflicts, then you can resolve them manually for each commit in feature's history. Once the conflicts are resolved and added to the index, you do

    $ git rebase --continue