rid
rid

Reputation: 63580

Overriding remote git repository with my repository

The remote repository contains a bad version. I have the copy of a good version locally. I want to replace everything that's on the remote repository with my current repository (the remote repository has a few more commits (including a merge) that should not have happened).

If I try to push, it tells me I need to pull first, but I don't want to do that, because that would mess my local version. I want the remote repo to contain what I have locally.

How can I do that?

Upvotes: 25

Views: 23610

Answers (2)

David Fells
David Fells

Reputation: 6798

  1. Make a new local branch from your known good version
  2. Pull
  3. Switch to the known bad branch
  4. Fully merge your known good branch into the known bad branch
  5. Commit and push

I usually use a process like this to preserve exactly what changed, have an isolated branch that's a known good copy, etc. It's probably excessive compared to using --force, but I prefer it.

Upvotes: 3

Amber
Amber

Reputation: 527378

Use the --force, Luke.

http://www.kernel.org/pub/software/scm/git/docs/git-push.html

Upvotes: 72

Related Questions