• 0

Replace the master branch with another branch in git

In the initial stage of a product when things are fickle and you are experimenting with different things, its possible that you might want to replace you master with your current branch once you settle on one technology. Although there is no way to directly designate your current branch to replace the master, you can however do this indirectly by using a merge strategy. If you checkout your current branch and merge the master into it with the 'ours' strategy, it has the effect of absorbing the master into your current branch but not using anything of the master. This way, when you checkout the master and do an ordinary fast forward merge of your feature branch, the merge commit will be exactly like your feature branch, effectively making it seem like you replaced the master with your feature branch.
git checkout feature_branch
git merge -s ours --no-commit master
git commit      # Add a message regarding the replacement that you just did
git checkout master
git merge feature_branch