Git push to remote repo , force overwrite

1185 views git
9

Before i do this just want some clarification:

git push -f origin develop

this will overwrite the branch on my remote repo called develop

Will i be able to revert back to the previous commit on remote repo after doing this?

answered question

1 Answer

11

Possibly not. You may lose some of your history.

If you have rewritten the history of your local repo such that the previous commit is gone, then once you force push those changes to the server you will not be able to get it back. Performing a force push makes the server copy match your local copy exactly, including any modifications to history.

If your goal isn't to rewrite history, I would recommend the following steps:

  1. Do a git pull to merge your remote repository with the remote repository. You will probably have merge conflicts.

  2. Resolve the merge conflicts by hand.

  3. Commit your resolution of the merge conflicts.

  4. Do a normal push once the merge conflicts are resolved.

posted this

Have an answer?

JD

Please login first before posting an answer.