Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot push to GitHub - keeps saying need merge

Tags:

git

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

Pushing to [email protected]:519ebayproject/519ebayproject.git To [email protected]:519ebayproject/519ebayproject.git  ! [rejected]        master -> master (non-fast-forward) error: failed to push some refs to '[email protected]:519ebayproject/519ebayproject.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

I have not pushed anything in the repository yet, so why do I need to pull something?

like image 934
user1353717 Avatar asked Apr 24 '12 12:04

user1353717


People also ask

Why can't I push to GitHub?

Simply put, git cannot make the change on the remote without losing commits, so it refuses the push. Usually this is caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.

How do I turn off merge in GitHub?

How do I cancel a git merge? Use git-reset or git merge --abort to cancel a merge that had conflicts. Please note that all the changes will be reset, and this operation cannot be reverted, so make sure to commit or git-stash all your changes before you start a merge.

How do I force a push to GitHub?

To force a push to only one branch, use a + in front of the refspec to push (e.g git push origin +master to force a push to the master branch).

What is the difference between push and merge?

Whats the difference between push , commit & fetch ,merge. Git commit basically “records changes to the local repository” while git push “updates remote refs along with associated objects”.


1 Answers

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.

like image 86
Nick Rolando Avatar answered Oct 12 '22 01:10

Nick Rolando