Git: Replace the master branch with a feature branch
A product team has to work on different features at a time. The team members may create different branches to push their code so that dependency on others’ code is minimum while developing a feature and merge it later before releasing the feature. It is possible that master branch may become irrelevant in this case and you might want to replace master branch altogether with a feature branch.
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 feature 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 seems like you replaced the master with your feature branch.
Step by step guide:
Checkout to the feature branch
git checkout feature_branch
Merge with master. If you want your history to be a little clearer, I’d recommend adding some information to the merge commit message to make it clear what you’ve done.
git merge -s ours --no-commit master
git commit # add information to the template merge message
Checkout to master and do a normal merge with feature branch
git checkout master
git merge feature_branch #fast-forward merge
These changes are done only in your local git repository. To push these changes to GitHub do: