0

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.
Community
  • 1
  • 1
octopusgrabbus
  • 10,555
  • 15
  • 68
  • 131

3 Answers3

1

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.

prusswan
  • 6,853
  • 4
  • 40
  • 61
0

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.

Igor Popov
  • 9,795
  • 7
  • 55
  • 68
0

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

Matt Greer
  • 60,826
  • 17
  • 123
  • 123
  • Basically, the directory from which I'm issuing the push is the latest. I want the remote to become the new repository. (And, yes, I'm new to git.) – octopusgrabbus Nov 30 '11 at 19:08
  • I recommend doing a `git fetch`, then do a `git diff master origin/master` and see what the differences are. If the differences are ok, do a `git pull` then do your `push` – Matt Greer Nov 30 '11 at 19:11
  • I don't want to merge. I want the local directory to become the master. – octopusgrabbus Nov 30 '11 at 19:12
  • then do `git push origin :master` (this blows away the remote master branch), then do `git push origin master` – Matt Greer Nov 30 '11 at 19:14