Cannot push to GitHub - keeps saying need merge

后端 未结 30 2264
天命终不由人
天命终不由人 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 01:03

    In my case, I had "mybranch" checked out, and had done git pull, so I couldn't figure out why the push wasn't working. Eventually, I realized that I was pushing the wrong branch. I was typing git push origin master instead of git push origin mybranch.

    So if you've already done git pull and still getting this message, make sure you're pushing the correct branch.

    0 讨论(0)
  • 2020-11-22 01:03

    I have resolve this issue at my GIT repository. No need to rebase or force commit in this case. Use below steps to resolve this -

    local_barnch> git branch --set-upstream to=origin/<local_branch_name> 
    
    local_barnch>git pull origin <local_branch_name>
    
    local_barnch> git branch --set-upstream to=origin/master
    
    local_barnch>git push origin <local_branch_name>
    

    hope it will help.

    0 讨论(0)
  • 2020-11-22 01:04

    Your branch should include the latest merged changes as soon as you notice them, but you haven't pulled the latest changes.

    git fetch 
    

    might be all that is needed. If that doesn't work, then you might need to:

    git pull <sharedRepo> <branch> --rebase
    

    If you don't have any merge conflicts, you should be able to push your changes successfully.

    git push <forkedRepo> <branch>
    

    If you encounter merge conflicts, you cannot solve them remotely in GitHub. You have to solve them locally and then push the resolutions with a force label because a merge conflict resolution changes history.

    git push <forkedRepo> <branch> -f
    
    0 讨论(0)
  • 2020-11-22 01:04

    I experienced the very same problem and it turned out I was on a different (local) branch than I thought I was AND the correct local branch was behind in commits from remote.

    My solution: checkout the correct branch, cherry-pick the commit from the other local branch, git pull and git push

    0 讨论(0)
  • 2020-11-22 01:05

    As the message tells you,

    Merge the remote changes (e.g. 'git pull')

    Use git pull to pull the latest changes from the remote repository to your local repository. In this case, pulling changes will require a merge because you have made changes to your local repository.

    I'll provide an example and a picture to explain. Let's assume your last pull from origin/branch was at Commit B. You have completed and committed some work (Commit C). At the same time, someone else has completed their work and pushed it to origin/branch (Commit D). There will need to be a merge between these two branches.

    local branch:                         --- Commit C 
                                        /
                                       /
                                      /
    origin/branch: Commit A ------ Commit B ---- Commit D
    

    Because you are the one that wants to push, Git forces you to perform the merge. To do so, you must first pull the changes from origin/branch.

    local branch:                         --- Commit C -- Commit E
                                        /               /           
                                       /               /             
                                      /               /               
    origin/branch: Commit A ------ Commit B ---- Commit D 
    

    After completing the merge, you will now be allowed to fast-forward origin/branch to Commit E by pushing your changes.

    Git requires that you handle merges yourself, because a merge may lead to conflicts.

    0 讨论(0)
  • 2020-11-22 01:07

    Have you updated your code before pushing?

    Use git pull origin master before you push anything.

    I assume that you are using origin as a name for your remote.

    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.

    0 讨论(0)
提交回复
热议问题