[ACCEPTED]-Is it neccessary to update git branch before merging it to develop / master?-git-merge

Accepted answer
Score: 12

It's not necessary to update your master 12 branch before you merge your feature branch 11 into it. However, that is not the best 10 practice. You are better off doing the 9 following:

  1. Pull master branch and sure it is up to date with your remote.
  2. Merge/rebase your master branch into your feature branch
  3. Fix any merge conflicts
  4. Merge your feature branch into master

Doing it this way will ensure 8 that your commits are the most recent in 7 the history and that any merge conflicts 6 are handled on the feature branch, not the 5 master branch. This keeps your master branch 4 clean and your history cleaner. The other 3 people using your repo will be happy.

The 2 commands will look like this:

  1. git checkout master
  2. git pull --rebase origin master
  3. git checkout feature1
  4. git rebase master
  5. fix any conflicts
  6. git checkout master
  7. git rebase feature1 // will rebase with no conflicts since you fixed them previously.

To elaborate 1 on what each command will do:

  1. jump to your version of master, which is outdated
  2. pull changes from repo and update master, applying any local changes master has on top (none, if you used branches for edits)
  3. jump back to your feature1 branch that's still based off the outdated "master"
  4. apply feature1 changes on top of master, which was updated in #2
  5. fix conflicts
  6. jump back to master, which is updated but still without your feature1 changes
  7. apply master changes on top of feature1, but since feature1 is a direct child of master, this just updates master again with your feature1 changes
  8. here you should consider git push to "publish" your changes to master to the repo

More Related questions