My current branch is my_branch
. Trying to push the 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 [email protected] 4ed90a6..52673f3 my_branch -> my_branch ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to '[email protected]' To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes (e.g. 'git pull') before pushing again. See the 'Note about fast-forwards' section of 'git push --help' for details.
Trying to git pull
results in:
$ git pull Already up-to-date.
Why I get this error? How could I resolve this problem and perform git push
successfully?
This might be happening because of some conflict files present in your repository . And you was still trying to check in files . So After that what happen , it will check in your local repository not in master repository . So u was not able to pull or check in anythings in master(head) repository .
A commit gets rejected and causes a failed to push some refs to error because the remote branch contains code that you do not have locally. What this means is that your local git repository is not compatible with the remote origin. Based on the above, your local machine is missing commits C and D.
One explanation would be that the latest commits have been done on another branch, as explained in "Git pull from my public repository not working". The other possibility is for you to be in a detached HEAD mode. That would make any git pull "up-to-date" since you are in any branch.
You need to pull before push, to make your local repository up-to-date before you push something (just in case someone else has already updated code on github.com ). This helps in resolving conflicts locally. 'origin' is a remote. You can use git remote --verbose to see all the remote configured under your git folder.
My current branch is my_branch.
That is your problem. When you pull, Git is telling you that your branch my_branch
is up to date, not master
, which is behind origin/master
making a fast-forward merge impossible.
In order to push master, you need to check out master
and pull. This will merge in the changes waiting on origin/master
and allow you to push your own changes.
git checkout master git pull # resolve conflicts, if any git push
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With