It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do I remove an unpushed commit in SourceTree?

Paul Thacker Mar 19, 2015

Hi, I'm using SourceTree with a Bitbucket repository. I recently made a bunch of experimental changes to my working copy, most of which I never want to check in. I eventually decided that it would be easiest to just reset my working copy to my last commit and start fresh from there–deleting any files I had added and undoing any changes I'd made to files already in the repository. I looked at some questions on-line, and it sounded like I could do this with remove and discard commands. This didn't work like I expected. I ended up with an unpushed commit in Sourcetree that looks like it deletes the files I merely wanted to remove changes from, and indeed, these were missing in my working copy. (I did make a local backup first, just in case.) Eventually, I was able to do a Checkout command on my last pushed commit, and got my working copy back to what I wanted.

So at the moment, my working copy has what I want, and the on-line repository has what I want. But when I open SourceTree, it still shows the unpushed commit, and I'm not sure how to get rid of it. Maybe I could push it and revert it somehow, but I'd prefer to just never push it to the on-line repository. I thought maybe I could use the command "Reset current branch to this commit", but it's not available when I right click on the last commit I pushed. The unpushed commit is marked as "master" and "1 ahead". The last pushed commit is marked as "HEAD" and "origin/master".

In case that description wasn't clear, I'll also include a screenshot of what I'm looking at. Thanks for any help!



3 answers

13 votes
Paul Thacker Mar 19, 2015

As I said, if I right clicked on the commit I wanted, the option "Reset current branch to this commit" was light grey and could not be selected. But I did finally figure it out. I had a "detached HEAD". I had to first use the command:

git checkout master

Only then could I use the command:

git reset --hard 564a24f

to get rid of the unpushed commit.

I wasn't familiar with the concept of a "detached HEAD", which made it difficult to search for a solution. But after some very circuitous searching, I found this page useful:

Ananta Murti Mar 07, 2017

Thanks! It saves my day!

shalon teoh Oct 23, 2018

Thanks you!!

Like José Sá likes this
5 votes
Rahul Soni Jan 21, 2018

I have written a detailed article with screenshots. Sharing in hope that it would help:

0 votes
Johannes Kilian Mar 19, 2015

It isn't possible in SourceTree via GUI-Elements.

You have to open a Terminal in SourceTree and do this via commandline as described above.

According to Izhar Aazmi's comment it II possible - You never stop learning .... wink

Izhar Aazmi Mar 19, 2015

Nope, this is not correct. It is totally possible using GUI. See

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Sourcetree

[dev team] Sourcetree for Windows 2019 Preview - Dark Theme

Hi folks, While the full post is over on our blog I'd like to share the dark theme we've got planned for 2019 here directly as well to keep the discussion going.  The ...

1,952 views 14 18
Join discussion

Community Events

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

Events near you