How to reset a branch to another branch with git?

this is how i did it with basic Git commands:

git checkout hotfixes
git reset --hard master
git push --force origin hotfixes

of course it’s important to notify everyone working on hotfixes. most likely they will have to delete their local copy and start from a fresh one. an alternative, less invasive idea is to create a new branch:

git checkout master
git branch -tb hotfixes-2 # this creates branch `hotfixes-2` from a copy of `master`
git push origin HEAD # this creates `hotfixes-2` on the remote server

Leave a Comment