Search code examples
githubgithub-pagesgithub-actionsgithub-for-windows

failed to push some ref to my remote repository


i am working on a project and i can't push my files from local machine to remote repository it's showing error when i try to push my repository

****! [rejected] master -> master (fetch first) error: failed to push some refs to ' .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 integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.****

after referring i also tried $git fetch origin and $ git merge origin YOUR_BRANCH_NAME then also it dosen't works


Solution

  • The solution to your problem has given in the instruction. You have to run "git pull" as the remote repository contains work that you do not have in the local repository.

    Running "git fetch" won't be enough as it only fetch the changes to the local repository and doesn't merge with your codes in the staging area.

    If for some reason you dont want to run "git pull", then you can try the alternative commands like following:

    git fetch 
    git merge FETCH_HEAD
    

    git actually runs the above two commands when you run "git pull". Here FETCH_HEAD is the the reference to the codes you just fetched in the local repository.

    Let me know if you don't understand any part.