how to replace master branch with another branch code example

Example 1: git replace branch with another

# overwrite master with contents of feature branch (feature > master)
git checkout feature    # source name
git merge -s ours master  # target name
git checkout master       # target name
git merge feature       # source name

Example 2: git replace master with branch

git checkout better_branch
git merge --strategy=ours --no-commit master
git commit -m "Replacing master branch with better_branch"
git checkout master
git merge better_branch
git push origin master