How to overwrite a branch in Git with master
If you want all changes from master
in dev_branch
, then:
git checkout dev_branch
git reset --hard master
This only works if other people haven't cloned the repository.
If you have dev_branch
pushed to a remote already, you have to do:
git push --force
To force-push to the remote. Warning: This will break the history of the branch for people who cloned it before! Then, other people will have to do a git pull --rebase
on the dev_branch
to get the changes.
You can also rename the dev branch to something old and then make a new branch from master
with the same name:
git branch -m dev_branch old_dev_branch
git branch -m master dev_branch
Or, use the ours
strategy — not sure why it wouldn't work for you:
git checkout master
git merge -s ours dev_branch
git checkout dev_branch
git merge master