How to fix the problem in Git: "Updates were rejected because the pushed branch branch is behind its remote instance"

I try to push commit to remote and get this error message:

$ git push origin master To git@git1.eu1.frbit.com :hbrosuru.git ! [rejected] ab68c0485d -> master (non-fast-forward) error: failed to push some refs to ' git@git1.eu1.frbit.com :hbrosuru.git' hint: Updates were rejected because a pushed branch tip is behind its remote hint: counterpart. Check out this branch and integrate the remote changes hint: (eg 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

I think that they are confusing me somewhere by pushing several local branches to this single remote branch, and I would like to basically figure out what is on the server and push the whole branch out of the fresh ones. Is this possible, or is there a better way to fix this error?

Ps. this remote branch is hosted on Fortrabbit, so I don’t have full access to the server to just delete the branch and create a new one, because the Fortrabbit deployment mechanism is based on Git.

+5
source share
1 answer

I would basically find out what is on the server and pull out a whole branch from fresh ones.

This probably means a power push. Note that force clicks are generally unsafe and should be avoided when clicking on a shared source code repository such as GitHub. But in this situation, when you try to upgrade a PaaS server, this is probably good.

You can visually visualize your branches with gitk , git log --all --graph --decorate or some other tool before you press force to make sure everything looks as you expect.

To force push the local master branch to the remote master origin origin branch, run

 git push --force-with-lease origin master:master 

The argument --force-with-lease will force the push to succeed only if your local branch is updated relative to the one you are pushing to. (This prevents accidentally overwriting commits that you are not aware of.) I highly recommend using the with-lease option whenever possible, instead of the old --force argument, which is less secure.

+8
source

Source: https://habr.com/ru/post/1202090/


All Articles