Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Giving "fetch first" error when trying to push

Tags:

git

push

fetch

I am having my first introduction to git through a class I am taking. I have a number of files in a directory on my computer and am able to stage and commit them without a problem. However, when I try to push files to my github repository, I keep on getting this message:

Pushing to https://github.com/BigMeanCat/CMDA
To https://github.com/BigMeanCat/CMDA
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/BigMeanCat/CMDA'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Can anybody help me out with what this means and how to fix it? I've seen a few people with similar problems online, but I am BRAND NEW to git and not familiar enough with git's command line language yet. I'm a little hesitant to take certain suggestions, as I don't know whether it will solve the problem or make it worse.

Thanks!

like image 248
FizzikalGrafiti Avatar asked Sep 16 '14 06:09

FizzikalGrafiti


People also ask

Why is my git push failing?

failed to push some refs to errors are often caused when changes are not committed before pushing, issues with Git pre-push hook, incorrect branch name, or the local repository not being in sync with the Git repository.

How do I fix error failed to push some refs to Origin?

We can fix the error: failed to push some refs to [remote repo] error in Git using the git pull origin [branch] or git pull --rebase origin [branch] commands. In most cases, the latter fixes the error.

How do I force git to push?

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).


1 Answers

I have been taken same error, then I solved this topic with used "--force" command. Briefly, write this command;

git push origin master --force

Attention: Probably, you tried to do push your codes over and over again before , that's why you took this error.My solution overwrite forcefully with your changeset. By this method your repository may cause mismatch other people's. But If you work alone (not like a group working), so you can use easily "--force" as I mentioned above.

like image 67
Purgoufr Avatar answered Oct 12 '22 21:10

Purgoufr