How to Replace Master Branch with Another Branch?

Suppose we have created a dev branch from the master branch and then the dev branch has got some new commits. So, now we want to keep only the dev branch’s codes in master branch except all the old codes from the master. Let see how we can do that –

Make sure that your local master is up to date with the master remote:

git checkout master
git fetch origin
git pull

And then we should use  “ours” merge strategy to overwrite master with dev branch. Like this –

git checkout dev
git merge -s ours master
git checkout master
git merge dev

The  -s ours is short for  –strategy=ours

Now, all the codes of dev branch’s should be in the master without its previous codes.

we can push/publish the master with git push origin master

Check the source code in your repository. 🙂