24

How do I remove commits, waiting to be pushed to remote?

2 pushes waiting

My situation is, that those queued commits (changes) been already pushed (more bellow) and now the server refuses to accept those as they are behind the HEAD.

I tried resetting to another commit, but when I go back to HEAD, pushes reappear again.

Clicking Repository > Refresh Remote Status won't help, it actually added the 2nd waiting push :)

PS: I apologize for my terminology, I'm quite new to git.

.

Update 1

Problems started when I were commiting feature2 to master branch. I don't have rights to commit there so it got stuck. Then I commited again to my personal branch, which was OK. Then I got one waiting commit, never to be pushed, even if I select the right (personal) branch when I click Push.

enter image description here

Community
  • 1
  • 1
teejay
  • 2,353
  • 2
  • 27
  • 36
  • Its not an error, its just warning that you files not moved to you git repository,Its shows count until the files are moved to Git repository – Snopzer Jun 14 '16 at 11:01
  • Possible duplicate of [Sourcetree - undo unpushed commits](https://stackoverflow.com/questions/23865335/sourcetree-undo-unpushed-commits) – Mark Schultheiss Jun 24 '19 at 18:29

2 Answers2

47

Git commits form a commit graph. Branches are just named pointers to commits in that graph.

Given that, your question can be restated as

My local master branch is pointing to a different commit than the remote master branch. How do I make my local master branch point to the same commit as the remote master branch?

There are two ways to accomplish this. Move the remote branch (git push) or move the local branch (git reset). As you said, you can't push to the remote master branch, so options 1 is off the table, that leaves option 2.

Note that the reset operates on the currently checkout branch1 so you'll first want to make sure you are currently on the master branch and then move that branch to the same commit as the remote master branch.

git checkout master               <--- make sure you're on the master branch
git reset --hard origin/master    <--- put your master branch on the same commit as origin/master

Now that master and origin/master are on the same commit, there should be no commits to push.


  1. reset operates on the current HEAD, but for the sake of this explanation it's easier to think of of it as operating on branches. For more information see this question: What is HEAD in Git? .
Community
  • 1
  • 1
Roman
  • 19,581
  • 6
  • 68
  • 84
  • for others > git said something about my personal branch and master branch being divergent > suggested to use "git pull" which merged those > then I followed steps above > all OK now – teejay Mar 16 '15 at 14:29
  • @teejay Which part is dark magic? I can update the answer until it's just boring 9 to 5 magic. – Roman Mar 17 '15 at 02:05
  • 1
    That is very kind of you, but I will stick to [git docs](http://git-scm.com/documentation) to "reverse engineer" this, so you could make more magic for those in need! :o) – teejay Mar 18 '15 at 15:20
4

Have you tried by doing: git reset --hard HEAD~1? In this way, you will have the head again on your local repo. Otherwise, I've seen a funny page that might be useful: http://ibrokegit.com/

Most of the times, this things should be solved by using the command line, instead of the GUI (in this case, SourceTree).

Hope it helps!

facundofarias
  • 2,973
  • 28
  • 27