简体   繁体   中英

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.

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). Then 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM