Cannot push to GitHub - keeps saying need merge

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

    I was getting the above mentioned error message when I tried to push my current branch foobar:

    git checkout foobar
    git push origin foo
    

    It turns out I had two local branches tracking the same remote branch:

    foo -> origin/foo (some old branch)
    foobar -> origin/foo (my current working branch)
    

    It worked for me to push my current branch by using:

    git push origin foobar:foo
    

    ... and to cleanup with git branch -d

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

    I had a similar issue and it turned out that my workflow for keeping my branch up to date was at fault. I was doing the following:

    In my local 'master'

    git fetch upstream
    git merge upstream/master --ff-only
    

    then back in my local branch

    git rebase master
    

    This worked well for a previous git flow but not with github. The git rebase was the problem here causing issues with syncing (and I'll admit that's something I've had to accept without fully understanding) and unfortunately put me in a position where git push -f became probably the easiest option. Not good.

    My new flow is to update the branch directly using git merge as follows:

    In my local branch

    git fetch upstream
    git merge upstream/master
    

    No fast forward, as I will have made changes of course in the local branch.

    As you can probably tell, I'm no git expert but I'm reliably informed that this workflow will probably avoid the specific problems that I had.

    0 讨论(0)
  • I was getting a similar error while pushing the latest changes to a bare Git repository which I use for gitweb. In my case I didn't make any changes in the bare repository, so I simply deleted my bare repository and cloned again:

    git clone --bare <source repo path> <target bare repo path>
    
    0 讨论(0)
  • 2020-11-22 00:44

    Is your branch name the same as the remote branch name?

    If no, you should checkout a new branch with the same name as the remote branch and try push it again.

    Assume the remote branch you want to push is [testing] and your local branch is named as [test].

    If you`re not in test branch, first switch to it.

    git checkout test
    

    Then open a new branch and name it testing.

    git checkout -b testing
    

    Now, it`s time to push it:

    git push [remote repo] testing
    
    0 讨论(0)
  • 2020-11-22 00:44

    Another cause of this problem (apparently not so common)...

    My server was behind ~12 hours when I did a push

    I configured NTP on the server SYNC my clock.

    I executed a new git push which led the error discussed in this post.

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

    First and simple solution:

    • Try this command git push -f origin master.
    • This command will forcefully overwrite remote repository (GitHub)

    Recommended Solution 1 :

    • Run these commands:
    git pull --allow-unrelated-histories  //this might give you error but nothing to worry, next cmd will fix it
    git add *
    git commit -m "commit message"
    git push
    

    If this doesn't work then follow along

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