This command that you used,
git push origin development:master
updates the master branch on the remote with the development branch locally, or in other words, it does a fast-forward merge of development into the master branch on the remote.
It does not "replace" work on the master branch, since it's not a force push with the --force
or the -f
options.
Solution
You can attempt to force push the master branch to the remote. Note that if another user has already pushed additional work onto the master branch since you fast-forwarded it to the development branch, than that user's work will be over-written by your force-push. However, if that work is based on the development branch instead of master, then it's already sort of invalid, in my opinion.
You can force push using
git push origin master -f
If you feel that you have to be extra safe when force-pushing so as to not over-write someone else's push, then you can use the --force-with-lease
(since Git version 1.8.5?)
git push origin master --force-with-lease
That will only force-push to the remote if the master branch is still in the same state that it was when you did your last push (the expected state, based on your local remote-tracking branch). Note that if you alter your remote-tracking branch with git fetch
, then you'll need to pass additional (documented) options to --force-with-lease
in order to do this correctly.
If someone happens to have pushed new work before this, then the master branch won't be in the "expected state", and the force-push will be rejected, as a safety feature.
Of course, if someone already fetched your accidentally pushed commits into their local repo, then they might still need to rebase their new work when you force push, if they based their new work on the accidental commits.
Alternative solution
Instead of force-pushing the master branch's previous state, you can choose to revert the commits instead, in case you cannot force-push the master branch (for example, if you simply cannot overwrite new commits pushed onto master, even though development was merged in by accident). However, once you are ready to actually merge in the development branch, you'll need to revert the changes made by your last revert, in order to restore the full changes of the development branch in master.
I will not go into the details of this solution here, because it's well documented at