Replace the master branch with another branch in git

In the ini­tial stage of a prod­uct when things are fickle and you are exper­i­ment­ing with dif­fer­ent things, its pos­si­ble that you might want to replace you mas­ter with your cur­rent branch once you set­tle on one technology.

Although there is no way to directly des­ig­nate your cur­rent branch to replace the mas­ter, you can how­ever do this indi­rectly by using a merge strategy.

If you check­out your cur­rent branch and merge the mas­ter into it with the ‘ours’ strat­egy, it has the effect of absorb­ing the mas­ter into your cur­rent branch but not using any­thing of the mas­ter. This way, when you check­out the mas­ter and do an ordi­nary fast for­ward merge of your fea­ture branch, the merge com­mit will be exactly like your fea­ture branch, effec­tively mak­ing it seem like you replaced the mas­ter with your fea­ture 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

Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *