Cannot push to GitHub - keeps saying need merge

后端 未结 30 2263
天命终不由人
天命终不由人 2020-11-22 00:09

I\'m new to GitHub. Today I met some issue when I was trying to push my code to GitHub.

Pushing to git@github.com:519ebayproject/519ebayproject.git
To git@gi         


        
相关标签:
30条回答
  • 2020-11-22 00:50
    git pull origin branch_name --rebase
    

    This worked for me -- the command git pull origin branch_name --rebase will pull changes from remote branch_name at first, then rebase current branch on the top of it.

    0 讨论(0)
  • 2020-11-22 00:51

    In addition to the answers above, the following worked for me : -

    Scenario -

    1. I pushed my_branch to origin successfully.
    2. I made few more changes.
    3. When I tried to push again, (after doing add, commit of course), I got the above mentioned error.

    Solution -

     1. git checkout **my_branch**
     2. git add, commit your changes.
     3. git pull origin **my_branch** (not origin, master, or develop)
     4. git push origin **my_branch**
    

    0 讨论(0)
  • 2020-11-22 00:52

    This problem is usually caused by creating a readme.md file, which is counted as a commit, is not synchronized locally on the system, and is lacking behind the head, hence, it shows a git pull request. You can try avoiding the readme file and then try to commit. It worked in my case.

    0 讨论(0)
  • 2020-11-22 00:54

    This can cause the remote repository to lose commits; use it with care.

    If you do not wish to merge the remote branch into your local branch (see differences with git diff), and want to do a force push, use the push command with -f

    git push -f origin <branch>
    

    where origin is the name of your remote repo.

    Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. This flag disables the check. This can cause the remote repository to lose commits; use it with care.

    0 讨论(0)
  • 2020-11-22 00:55

    The problem with push command is that you your local and remote repository doesn't match. IF you initialize readme by default when creating new repository from git hub, then, master branch is automatically created. However, when you try to push that has no any branch. you cannot push... So, the best practice is to create repo without default readme initialization.

    0 讨论(0)
  • 2020-11-22 00:56

    Some of you may be getting this error because Git doesn't know which branch you're trying to push.

    If your error message also includes

    error: failed to push some refs to 'git@github.com:jkubicek/my_proj.git'
    hint: Updates were rejected because a pushed branch tip is behind its remote
    hint: counterpart. If you did not intend to push that branch, you may want to
    hint: specify branches to push or set the 'push.default' configuration
    hint: variable to 'current' or 'upstream' to push only the current branch.
    

    then you may want to follow the handy tips from Jim Kubicek, Configure Git to Only Push Current Branch, to set the default branch to current.

    git config --global push.default current
    
    0 讨论(0)
提交回复
热议问题