1

I am trying to put my project on github following instructions given here:https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line

But is not allowing me to push my project on github showing error:failed to push some refs to . It also shows following hints.

hint: Updates were rejected because the tip of your current branch is to be
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

**

I have tried to figure out the meaning of it but failed.

Please help me

1 Answers1

1

That happens if you have created a non-empty GitHub repo (ie one with a README.md, a .gitignore and a LICENSE file): it has at least one commit of its own.

One easy solution is to delete/recreate your GitHub repo (if it was a new one), selecting the option to create an empty repo.
Simpler (if you don't want to keep the GitHub repo history)

git push --force -u origin master

If you cannot touch the GitHub repo, then you must precede your git push with:

git pull --rebase origin master

Then you can do a:

git push -u origin master

Note the -u option: see "Why do I need to explicitly push a new branch?" for more.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Why not a simple force-push? Does GitHub not support that? –  Sep 03 '14 at 11:32
  • @hvd it does, I simply don't know if the OP want to keep the files or not. I'll edit the answer. – VonC Sep 03 '14 at 11:33
  • @VonC But why is it necessary to create empty Github repo?? I am new to github as well as git so it would be great if you can answer my question. –  Sep 03 '14 at 12:30
  • @user297666 because your error message is the direct result of a non-empty repo, with an history of its own. you need to erase that history with the one you made on your local repo (push --force), or rebase your work on top of the history from the GitHub (pull --rebase), or push to an empty repo (delete/recreate) – VonC Sep 03 '14 at 12:37
  • Got my answer.This:"Why do I need to explicitly push a new branch?" helped a lot. Thanks for providing it. –  Sep 03 '14 at 12:41