Home > Others > GIT: Replace the master branch with working branch

GIT: Replace the master branch with working branch

There is no direct way to replace the master branch of your git project with the working branch (or any other branch), but with the ‘ours‘ strategy of the GIT, you can achieve this task. This strategy will replace the master branch entirely with the working branch.

Lets do this step by step:

Checkout the working branch (say working_branch)

git checkout working_branch

Merge with master with ours strategy

git merge -s ours master

You can add some comment to keep the track of what we are doing.

Now checkout the master branch

git checkout master

And finally merge your working branch with the master branch

git merge working_branch

Now your master branch has been replaced with the working branch, now you can push your master code to GIT.

git push origin master