Git merge with force overwrite

前端 未结 6 665
悲哀的现实
悲哀的现实 2021-01-29 19:03

I have a branch called demo which I need to merge with master branch. I can get the desired result with following commands:

git pull or         


        
6条回答
  •  孤独总比滥情好
    2021-01-29 19:27

    These commands will help in overwriting code of demo branch into master

    git fetch --all
    

    Pull Your demo branch on local

    git pull origin demo
    

    Now checkout to master branch. This branch will be completely changed with the code on demo branch

    git checkout master
    

    Stay in the master branch and run this command.

    git reset --hard origin/demo
    

    reset means you will be resetting current branch

    --hard is a flag that means it will be reset without raising any merge conflict

    origin/demo will be the branch that will be considered to be the code that will forcefully overwrite current master branch

    The output of the above command will show you your last commit message on origin/demo or demo branch

    Then, in the end, force push the code on the master branch to your remote repo.

    git push --force
    

提交回复
热议问题