0

I can neither find my files in my local repository nor in github repository after I did some commands in linux command line. Here is the command that I've used.

$ git init
$ git config user.name 4everZard
$ git config user.email bryanwu610@gmail.com
$ git add *
$ git commit -m 'First commit'
$ git remote add origin https://github.com/4everZard/pdfeditor
$ git remote -v
$ git push origin master

and here is the info I get from the terminal :

Username for 'https://github.com': 4everZard
Password for 'https://4everZard@github.com': 
To https://github.com/4everZard/pdfeditor
! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/4everZard/pdfeditor'
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.

After I've done this, I can't find my files anymore. I'm totally fresh to github, please help! Thanks:)

edit: Problem has been solved. This problem is due to that I created another HEAD, so that origin head became detached head. Once I realize that, I create a new temporary HEAD and pull it back to origin master, then everything solved. Thank you everyone.
some links may help to those meet the same problem: How can I reconcile detached HEAD with master/origin?
Github "Updates were rejected because the remote contains work that you do not have"

Bryan
  • 1
  • 2
  • Possible duplicate of [git: updates were rejected because the remote contains work that you do not have locally](https://stackoverflow.com/questions/24357108/git-updates-were-rejected-because-the-remote-contains-work-that-you-do-not-have) – phd Oct 23 '17 at 23:02

1 Answers1

0

It looks like there's a default README.md file in your repo. Try overwriting it by force-pushing:

git push --force origin master

Note that you shouldn't need to use --force every time, since Git will start tracking the relationship in subsequent commits after your first one :)

Chris Long
  • 3,007
  • 4
  • 30
  • 37
  • I see a bunch of new files in [the repo](https://github.com/4everZard/pdfeditor): `.classpath`, `.project`, `pom.xml` and three new root level folders. Are you sure it didn't work? :) – Chris Long Oct 25 '17 at 01:14
  • Thank you for your help! However, actually your method didn't work. I think my problem is due to I created a new HEAD after commited my projects to repo and the origin HEAD became a detached head, so that it seems that my files was missing. I figured out that later and managed to fix it. – Bryan Oct 25 '17 at 15:08