Overwrite everything in master with another branch in git

后端 未结 4 1912
迷失自我
迷失自我 2021-01-11 10:20

I have a very out of date master branch in a git repository.

All of my work has been done in another branch.

What is the best way to merge the

4条回答
  •  臣服心动
    2021-01-11 10:47

    If you are fine with losing the history of your master branch you just let master point to the head of your current branch (your don't "overwrite" master - the branch - per se):

    git checkout yourotherbranch
    git branch -D master
    git checkout -b master
    

    Of course if you have a remote clone, you'll then have to

    git push -f origin master 
    

    Nota bene: this specifically applies to replacing the whole of your master branch and throwing the old master away as the title suggests. Otherwise, you should be fine with git merge master --strategy=ours.

提交回复
热议问题