I've pushed a few commits to origin/master instead of side branch. I reverted my local master to the commit I want. Obviously I can't pull and then push because that would bring in undesired changes. I can't push straight away either, because my local branch is behind a few commits. Now how can I push it to origin and overwrite it?
At the command line: git push -f
I'm not sure if there's a way to do it from SourceTree - I'm not seeing one right off hand.
Use that command very judiciously, though. If anyone else has pulled the bad commits on to their local repositories, you would be better off reverting the commits rather than "deleting" them.
Also it is possible that your remote may be configured to reject force pushes, in which case this won't work.
To push any arbitrary commit-id to origin/master from the command-line, here's the command (this forces origin/master to become the exact commit-id specified):
git push --force origin <commit-id>:refs/heads/master
git push --force origin 6fe08acd2f:refs/heads/master
Also note that in Git there is an important difference between the "reset" command and the "revert" command. The reset command moves the HEAD back to a previous commit. The revert command creates a new commit on the end of a branch that undoes the changes made by a specific commit (without actually removing that commit from the graph, therefore avoiding rewriting history).
Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events