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 r
Just do:
git push origin <your_branch_name> --force
or if you have a specific repo:
git push https://git.... --force
This will delete your previous commit(s) and push your current one.
It may not be proper, but if anyone stumbles upon this page, thought they might want a simple solution...
Also note that -f
is short for --force
, so
git push origin <your_branch_name> -f
will also work.
If I'm on my local branch A, and I want to force push local branch B to the origin branch C I can use the following syntax:
git push --force origin B:C
I had the same question but figured it out finally. What you most likely need to do is run the following two git commands (replacing hash with the git commit revision number):
git checkout <hash>
git push -f HEAD:master
I would really recommend to:
push only to the main repo
make sure that main repo is a bare repo, in order to never have any problem with the main repo working tree being not in sync with its .git
base. See "How to push a local git repository to another computer?"
If you do have to make modification in the main (bare) repo, clone it (on the main server), do your modification and push back to it
In other words, keep a bare repo accessible both from the main server and the local computer, in order to have a single upstream repo from/to which to pull/pull.
use this following command:
git push -f origin master
First of all, I would not make any changes directly in the "main" repo. If you really want to have a "main" repo, then you should only push to it, never change it directly.
Regarding the error you are getting, have you tried git pull
from your local repo, and then git push
to the main repo? What you are currently doing (if I understood it well) is forcing the push and then losing your changes in the "main" repo. You should merge the changes locally first.