revert origin/master to my local master

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?



3 answers

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.


"Forced push" is not accessible in windows version of Sourcetree - see:

You should be able to do it from Git Bash (command line), though, if it hasn't been disabled on your remote. Again, you should use it judiciously, if at all.

Thank you Tim,

I'll investigate further.

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).

I am not fan of git... but no option and forced to use...


I have same question how do revert my change or change committed file without creating another change list

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

647 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you