Why do i get “error: failed to push some refs”?

前端 未结 5 632
陌清茗
陌清茗 2020-12-31 11:59

I have a remote git repository and a local one that i work with. Whenever i do any changes locally, i push them to the remote. Then i sometime do a \"git commit\" on the rem

相关标签:
5条回答
  • 2020-12-31 12:12

    I faced similar problem, and the following command worked. git push --set-upstream origin master

    0 讨论(0)
  • 2020-12-31 12:26

    this always means that you didn't synchronize the remote repository with local repo,so first you should synchronize them by using command git pull as following:

    git checkout master    
    git pull origin master 
    

    after this process ,you will synchronize them ,and then you can push changes to remote repo by followings:

    git add [filename/directory]  
    git commit -m"input your message"   
    git remote add origin https://github.com//yourname.git     
    git push origin master
    
    0 讨论(0)
  • 2020-12-31 12:27

    I have also faced same error and wasted lots of time, Here is final solution.

    1. when use git push origin master then we get error so solution is to force push. so use second option. it worked for me.

    2. git push origin master --force

    0 讨论(0)
  • 2020-12-31 12:33

    What you should be doing is creating the remote repository as a bare repository. A bare repository is just the git repo, without a current checkout (that is, it is like just the contents of the .git dir in a regular Git repo, so it contains objects and refs, but it doesn't have an index or working copy of the file hierarchy). If you try pushing to a non-bare repository, the working copy will get out of sync with what is committed, and cause the kinds of problems you are seeing here.

    You can create a bare repository using git init --bare repo.git. Or you can clone an existing repository as a bare repo using git clone --bare original-repo new-repo.git.

    If you want to have a checked out copy of the repository on your server, you will need to create a new, non-bare repo on the server, and then pull into that repo from the bare repo that you push to.

    0 讨论(0)
  • 2020-12-31 12:35

    Here is another option.

    git reset --mixed origin/master
    git add .
    git commit -m "Your message"
    git push origin master
    
    0 讨论(0)
提交回复
热议问题