Git Replace Master Branch Entirely with Another Branch

In this post I will show you how to replace master branch in git with entirely a different branch. Suppose you have a master branch and you checkout a new refactoringBranch from it with an intention to merge it with master after minor tweaks. However you end up working on the refactoringBranch for a long time.

I came across this scenario when i was working on a web app and switched to a new branch and used yeoman webapp generator in it. I ended up changing all the files and my previous code became obsolete.

You should be able to use the “ours” merge strategy to overwrite master with refactoringBranch like this:

git checkout refactoringBranch
git merge -s ours master
git checkout master
git merge refactoringBranch

The result should be your master is now essentially refactoringBranch.

This content has been helpful to you?

Thanks for contributing!

Yes No