简体   繁体   中英

Remove everything from the master branch

I have two branches - develop and master. I worked constantly on the dev branch and the master is completely unnecessary code, quite different than on dev branch.

how to transfer everything from dev to master in such a way that nothing is left of the old master ?

You can delete the master branch. And then create a new master from dev branch.

Here's how you can achieve this:

git checkout develop
git branch -D master
git checkout -b master

If you want to push your new master branch to remote, then you can use force push option, it will overwrite the old master from the remote.

git push origin -f master

There are three options:

First - if you want to destroy every trace of the history of master you can just set master to dev -- similar to the answers of @Krantisinh and @ashishmohite:

git branch -f master dev

If other people have build upon the old state of master they are screwed. So talk to them before you do that.

Second - you want to keep the history of master but swap out the contents: Then you are doing a special merge like this:

git checkout master

# git merge -s theirs simulation
git merge -s ours dev
git branch temp_THEIRS 
git reset --hard dev
git reset --soft temp_THEIRS
git commit --amend
git branch -D temp_THEIRS

This merges dev into master but takes all content from dev -- no conflicts - no questions asked. This comes from https://stackoverflow.com/a/56368650/947357 .

Third - (as per comment) if you want to throw away master (as in "First") but also start master without any history:

git checkout --orphan new-master
git commit -m "start from scratch again"
git branch --force -M new-master master

After that dev and master do not share any history.

You could delete master branch if it's not locked and then checkout the master branch from develop

git checkout dev
git branch -D master
git checkout -b master

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