git error push origin master

When the first time you use Git as version control you might be get error ” failed to push some refs to“, So in this tutorial i am gonna to show to you how to fix failed git push origin master.

Git Error Message

One of the common error in git is failed to push some refs to with detail error :

error: failed to push some refs to 'https://github.com/xxxx/xxxx.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g., hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Error push origin master
git error failed to push some refs to
Git Error Push Origin Master

Do not panic, never assume that you will not allow to commit your changes. Let’s me quick explain, that’s commonly happened when you first time use git as control version, and you collaborate your project with your team, once your team commit with such add new file to repository, and the other hand your local project not getting update to get that file, so between your local project and repository is not equal, and git will detect it and assume that you local is left behind when you try to push your commit, that’s why you got an error.

If you notice in that error, there are so many hint. There are 2 option you can do to fix that problem, first just type “git pull” and second type “git pull origin master –allow-unrelated-histories“. so what the different between them?

Git Pull

  1. git pull
    By follow the hint that appear in error message by type “git pull“, it will fix your problem, but if the condition above happen again, your local branch and repository is not equal, the error will coming to you again and you should to running this command again to fix your problem, (that quiet annoying).
  2. git pull origin master –allow-unrelated-histories
    This command that i’m really recommend, by typing git pull origin master –allow-unrelated-histories you will not see error anymore.
    Even though your local branch is not updated and left behind from repository, once you push again you commit.

Here we are trying to use command git pull origin master –allow-unrelated-histories

git pull origin master --allow-unrelated-histories

Once you running, let’s do push again.

Git Tortoise Push
Git Push
Git Push  success

Congratulation.

HAPPY SHARE…!!!

Advertisements
Share: