18

I have a local git repo on my workstation which I push to a dropbox location so that I can pull it down to my laptop via git pull remote dropbox.

Yesterday I checked in a change on my workstation, committed it and git push dropbox'ed it. I did not do a git pull from my laptop because I suspected that I was going to end up throwing that commit away.

Today I decided to throw that commit away, so on my workstation I did:

git reset --hard HEAD~1

So far, so good. Now I want to push this back up to Dropbox, so that on my laptop I can merge and commit from there. So on my workstation I tried:

git push dropbox

And git complained that:

! [rejected] master -> master (non-fast-forward) error: failed to push some refs to '\My Dropbox\dev\repos\xcast.git' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.

How do I get my worstation and Dropbox back in sync again?

John Dibling
  • 99,718
  • 31
  • 186
  • 324

1 Answers1

32

Force push should work: git push -f dropbox

Git is complaining because your remote still has that extra commit, and thus you are behind it in terms of history.

jli
  • 6,523
  • 2
  • 29
  • 37
  • 1
    Are there any negative repercussions of doing this? – John Dibling Jul 13 '12 at 15:07
  • @Grunch: yes, you lose the commit in the remote. If you've shared that commit with anyone else, histories may diverge. – Fred Foo Jul 13 '12 at 15:08
  • 1
    @Grunch Yeah, only ever force push if you're sure no one has already pulled the changes (or you're the only one with access) – jli Jul 13 '12 at 15:09
  • @larsmans: The remote is shared among all my own computers. I did not do a pull from the remote on any of those other machines since yesterday's ill-fated commit. Does that mean that in this case, histories will not diverge? – John Dibling Jul 13 '12 at 15:10
  • @Grunch You should be fine if they haven't pulled yet. – jli Jul 13 '12 at 15:11
  • @Grunch Take a look at http://stackoverflow.com/questions/253055/how-do-i-push-amended-commit-to-the-remote-git-repo/255080#255080 – jli Jul 13 '12 at 15:11
  • @jli: Great, thanks. Once I do this and try to do a pull from the remote on my laptop, should I expect git to say "already up to date"? – John Dibling Jul 13 '12 at 15:11
  • @Grunch Yeah that should be the case. – jli Jul 13 '12 at 15:12