Samuel Robert Samuel Robert - 10 months ago 48
Git Question

How to add some specific commits from master to another branch on git

I've this work flow with git. origin/master is 7 commits ahead of my branch "crazy-work" and crazy-work has 10 new commits. Now I want to merge crazy-work to origin/master. What is the best way to do this with minimal conflicts. even if there any conflict occurs choose the crazy-work branch's files as selected work. note that the branch crazy-work has the updated and stable source code.

Here is a little diagram

origin/master ------ a --- b --- c --- d --- e --- f ----?
\ /
\ crazy-work /
\___ h ___ i ___ j ___ k/

Answer Source

You can directly merge crazy-work to master, or you can first rebase crazy-work to master, resolving all the conflicts, and then merge it cleanly.

Scenario 1

git checkout master
git merge crazy-work

Scenario 2

git checkout crazy-work
git rebase master
#  possibly fixing conflicts, followed by
#  git rebase --continue
git checkout master
git merge crazy-work