R. Gore
R. Gore

Reputation: 55

How to make my Master branch my Head, and create a new master

We started a new project, a couple of months ago. We made a master branch, but actually used this as a develop/head branch. So this is full of commits you wouldn't want in your master. We actually have no head branch.

What I want, is to create a head branch, this should have all the commits of the current master branch, and then create a new master branch. I see some other examples of partly similar questions, but don't want to just try things and mess stuff up.

Upvotes: 1

Views: 188

Answers (1)

SwissCodeMen
SwissCodeMen

Reputation: 4885

Just pull the newest changes from the current master-branch by git pull. Now you are on the Head.

Then you must renaming the current master-branch to develop-branch (because there must not be branches with the same name) with git branch -m develop (but you must checkout the branch, where you want to rename).

Now you must push the new/renamed branch to remote with git push origin -u develop and remove the old one: git push origin --delete master.

Now you can create the new one with clean commit-history with simple git checkout --orphan -b master and push it to remote with git push -u origin master. (about --orphan flag, read the documentation).

And now you can git merge from develop-branch to master-branch if you need it without having every single commit in the master-branch.

Upvotes: 2

Related Questions