0

I recently did a hard reset of my local git repository: In other words I reset it to an earlier point in time. Now when I try to push up to the origin it tells me that it can't because the origin contains work of a later date than my repository. This makes sense, but I don't care about the work the origin has after my local repository.

If I first pull, which is what I am told to do, I presume that my local HEAD will then become whatever the origin HEAD was, i.e. with the additional work and my hard reset will be for nought.

How should I proceed here? To recap, I don't care about the additional later work on the origin, but do care about the extra work on the local done after the hard reset.

I am beginning to think that hard resets are not a great idea.

TimWolla
  • 31,849
  • 8
  • 63
  • 96
sectornitad
  • 973
  • 3
  • 11
  • 20
  • pull should do a fetch then a merge, so you should be ok. worst case (if this doesn't work) is that you'd have to do the hard reset again. – jdigital Mar 12 '14 at 23:22
  • @jdigital And after the hard reset he will face the same issue again ;) – TimWolla Mar 12 '14 at 23:25
  • @TimWolla right. i was trying to say that it's worth trying a `pull` because it won't make things any worse. – jdigital Mar 12 '14 at 23:28

1 Answers1

0

You can push --force to override the current HEAD of the origin, even if your local branch is not a descendant of it.

However: You should be aware of the consequences: Other developers working on the same repository now cannot easily pull in the changes, but have to reset / rebase to the origin. Using forced pushes / rewriting pushed history is bad and should be avoided whenever possible.

See also another answer here on StackOverflow on the dangers of forced pushes: How to properly force a Git Push?

Community
  • 1
  • 1
TimWolla
  • 31,849
  • 8
  • 63
  • 96