Why is git push rejected? ("git pull" doesn't help)

My current branch is my_branch . Trying to make changes to the remote repo, I get:

 $ git push Counting objects: 544, done. Delta compression using up to 4 threads. Compressing objects: 100% (465/465), done. Writing objects: 100% (533/533), 2.04 MiB | 1.16 MiB/s, done. Total 533 (delta 407), reused 0 (delta 0) To git@......git 4ed90a6..52673f3 my_branch -> my_branch ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to ' git@......git ' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (eg 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details. 

Trying git pull results in:

 $ git pull Already up-to-date. 

Why am I getting this error? How can I solve this problem and execute git push successfully?

+4
source share
2 answers

My current branch is my_branch.

It's your problem. When you pull, Git tells you that your my_branch branch my_branch updated, not master , which is behind origin/master , which makes fast merging impossible.

To click master, you need to check master and pull. This will merge the changes awaiting origin/master and allow you to make your changes.

 git checkout master git pull # resolve conflicts, if any git push 
+14
source

[If your main branch is already configured to redirect when clicked, you just need to do pull the main branch, as described in another answer, but otherwise:]

If you receive a message without fast forwarding, this means that you can only commit over the existing commits, but you are trying to do otherwise. Reinstall the wizard before clicking (assuming the remote is called a source):

 git checkout master git pull --rebase origin master git push 

See also this question: git rebase and git push: non-fast forward, why use?

+3
source

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


All Articles