I've set up a remote non-bare "main" repo and cloned it to my computer. I made some local changes, updated my local repository, and pushed the changes back to my remote repo. Things were fine up to that point.
Now, I had to change something in the remote repo. Then I changed something in my local repo. I realized that the change to the remote repo was not needed. So I tried to git push
from my local repo to my remote repo, but I got an error like:
To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes before pushing again. See the 'Note about fast-forwards' section of
git push --help
for details.
I thought that probably a
git push --force
would force my local copy to push changes to the remote one and make it the same. It does force the update, but when I go back to the remote repo and make a commit, I notice that the files contain outdated changes (ones that the main remote repo previously had).
As I mentioned in the comments to one of the answers:
[I] tried forcing, but when going back to master server to save the changes, i get outdated staging. Thus, when i commit the repositories are not the same. And when i try to use git push again, i get the same error.
How can I fix this issue?
git push -force
more carefully. – Comeauxgit push --force
is indeed another valid way to force push, and will push branches just as well asgit push origin master --force
with Git's defaultpush.default config settings
, though which branches specifically get pushed differs between Git versions prior to 2.0 versus after 2.0. – Troikagit push --force
works fine these days, FWIW... – Muskygit push --force-with-lease
works even better :), it will refuse to update a branch unless it is the state that you expect. (see developer.atlassian.com/blog/2015/04/force-with-lease) – Polyzoicgit push origin some_branch --force
but it always returnedEverything is up-to-date
message. But,git push origin your_branch:some_branch --force
and this was what I was missing. Hope it helps! – Landsknecht