octopusgrabbus
octopusgrabbus

Reputation: 10695

How to resolve this git error

Ooops! Please forgive the error. I mixed apples and oranges (two different projects). Thanks for the answers. They're not wasted.

My whole purpose in asking this question is I am trying to take a development directory and transfer it out to a server, from which I will then update in the future using git commit.

I got a great solution from this question specifically Josh Lindsey's answer. It worked fine for one project I have, but for another I got some errors, and want to know the best way to fix them.

I did follow the instructions for initializing the remote directory.

When I issue the git push origin master command from the local directory, I get these errors.

amr@h2oamr:~/bin$ git push origin master
cvsuser@h2oamr's password: 
To cvsuser@h2oamr:/home/cvsuser/master_source_repository_git/ics/addr_verify_clj.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'cvsuser@h2oamr:/home/cvsuser/master_source_repository_git/ics/addr_verify_clj.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

Upvotes: 0

Views: 415

Answers (3)

prusswan
prusswan

Reputation: 7101

Depending on what you really want to do, you have two other options apart from what has already been suggested:

  1. git fetch to update the status of the remote branch without automatic merge

  2. git push -f or git push --force to push your local branch onto the remote branch and overwrite its existing head regardless of the consequences (even if your local branch is outdated as compared to it)

Usually I will do 1 before deciding whether to do 2.

Upvotes: 1

Matt Greer
Matt Greer

Reputation: 62057

This happens when you are trying to push to a remote repo when your view of that repo is out of date. Someone else pushed to that repo, and your local git's view of that repo is a commit (or few) behind. So that would require git to merge your changes into the remote repo. Git doesn't want to do that, as that's better done by a human.

So git is telling you to do a pull. That will get your local view of the remote repo up to date, allowing you to then cleanly push your changes into it. This will likely require you to merge, which is a manual/human oriented process. Git was designed to ensure manual/human type things are done by humans.

TL;DR: do a git pull, merge changes if needed, then push again. Just like the error message says

Upvotes: 0

Igor Popov
Igor Popov

Reputation: 10101

First you need to do a git pull to get the latest changes from the remote repository. This will do an automatic merge (and after solving possible conflicts) and you will be able to push your code back to the remote.

Upvotes: 0

Related Questions