3

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....

leezer3
  • 240
  • 4
  • 10
  • 1
    Merge `master` into feature or rebase feature onto `master`. – user4003407 Nov 10 '16 at 16:09
  • 2
    Possible duplicate of [Git merge master into feature branch](http://stackoverflow.com/questions/16955980/git-merge-master-into-feature-branch) – JamesD Nov 10 '16 at 16:29
  • Shameless plug: Here's [my answer](http://stackoverflow.com/a/42666870/3345375) to the duplicate question. Basically, you use a new branch: create the branch from master, merge your feature into it, and then use it to work on your feature going forward. – jkdev Mar 08 '17 at 09:10

1 Answers1

9

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
    
Code-Apprentice
  • 69,701
  • 17
  • 115
  • 226