3

I sometimes find I'm working on a branch and I want to merge all changes from the branch into my master branch so that master is essential a clone of the branch I was just working with. Is there an easy way to update master so that all the changes from the branch are merged into the master. The behavior I am looking for is that master would become an exact clone of the branch. I usually merging individual conflicts one at a time into master, but is there an easier way to do this? Thanks for your time.

drbunsen
  • 10,139
  • 21
  • 66
  • 94

2 Answers2

1

git reset --hard with the id of the commit you want to be your new master head should be your solution.

http://git-scm.com/2011/07/11/reset.html

EDIT : I'll flag it at duplicate : How to replace master branch in git, entirely, from another branch?

Look at the solution in the duplicate I mention. But depending on the desired result, the reset I suggested may be the solution.

Community
  • 1
  • 1
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
1

If you want to keep history, use the ours merge strategy:

git checkout branch
git merge -s ours master

If you don't care about the history of your master branch, reset it:

git checkout master
git reset --hard branch

(This will discard all your local changes and makes master's commit unreachable!)

If you don't have any commits in master that are not in your branch, you can fast-forward master to your branch:

git checkout branch
git merge master
# or `git merge --ff-only master` to only allow fast-forward
knittl
  • 246,190
  • 53
  • 318
  • 364
  • The last example will merge master into branch, rather than the other way around, will it not? And should that flag have been `--ff-only`? – SpinUp __ A Davis Jun 27 '18 at 17:10
  • @spinup: yes, `--ff-only`, thanks for pointing that out :) as for the direction of the merge, the OP asked "[so] that master would become an exact clone of the branch" which is what the commands do – knittl Jun 27 '18 at 21:42