Git - move branch to master

Rostyslav Druzhchenko picture Rostyslav Druzhchenko · Apr 6, 2012 · Viewed 11.5k times · Source

I have a branch with actual sources and I did not make any commits for a long time to master, and at the moment it's completely out of date. I want to just replace master's content with the content of my branch. One way to do it is to checkout both branch and master, delete master's content and copy content from branch to master, and after that push result to master.

It works, but I believe there has to be some git command to do it in a simpler way.

Does anybody know how to do it?

Answer

Andy picture Andy · Apr 6, 2012

You can use the following command to have master point to a new location:
git branch -f master branchToMoveMasterTo

What this is actually doing is creating a new branch called master that points to branchToMoveMasterTo. Since we already have a branch called master, we need the -f flag to say we want to delete the original master