Ricky Robinson
Ricky Robinson

Reputation: 22893

non-fast-forward error in git

I want to use git in my existing project, so I created a space on github for it and in the project folder on my host I did the usual:

$ git config --global user.name myname
$ git config --global user.email "[email protected]"
$ cd myProjectFolder/
$ git init
$ git add .
$ git commit -m "first commit"
$ git remote add origin https://github.com/myusername/myprojectname.git

And then I want all the files of my project to be also on the online repository:

$ git push origin master

But I got the following much-dreaded error:

To https://github.com/myusername/myprojectname.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/myusername/myprojectname.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.

Now, there is nothing I have to pull from the online repository, since there is still nothing over there. Why should I pull?

Anyhow, what exactly should I do here to have all my files online and start using git?

Upvotes: 0

Views: 136

Answers (1)

eckes
eckes

Reputation: 67037

After git remote add, the URL of teh remote repo is known in yours but not yet it's content.

After git fetch origin (or git pull), you'll be able to git push since then the content of the remote repo will be known.

Upvotes: 1

Related Questions